File tree Expand file tree Collapse file tree 2 files changed +42
-27
lines changed Expand file tree Collapse file tree 2 files changed +42
-27
lines changed Original file line number Diff line number Diff line change 2
2
Title : Collections.OrderedDict()
3
3
Subdomain : Collections
4
4
Domain : Python
5
- Author : Ahmedur Rahman Shovon
5
+ Author : Md Samshad Rahman
6
6
Created : 15 July 2016
7
- Updated : 08 February 2023
7
+ Updated : 26 November 2024
8
8
Problem : https://www.hackerrank.com/challenges/py-collections-ordereddict/problem
9
9
"""
10
10
11
- import collections
12
- import re
11
+ from collections import OrderedDict
13
12
14
- n = int (input ())
15
- item_od = collections .OrderedDict ()
16
- for _ in range (n ):
17
- record_list = re .split (r"(\d+)$" , input ().strip ())
18
- item_name = record_list [0 ]
19
- item_price = int (record_list [1 ])
20
- if item_name not in item_od :
21
- item_od [item_name ] = item_price
22
- else :
23
- item_od [item_name ] = item_od [item_name ] + item_price
24
- for i in item_od :
25
- print (f"{ i } { item_od [i ]} " )
13
+
14
+ if __name__ == '__main__' :
15
+ ordered_dictionary = OrderedDict ()
16
+
17
+ n = int (input ())
18
+
19
+ for _ in range (n ):
20
+ s = list (input ().split ())
21
+ price = int (s [len (s ) - 1 ])
22
+ name = ' ' .join (s [:len (s ) - 1 ])
23
+
24
+ if ordered_dictionary .get (name ):
25
+ ordered_dictionary [name ] += price
26
+ else :
27
+ ordered_dictionary [name ] = price
28
+
29
+ for key , value in ordered_dictionary .items ():
30
+ print (key , value )
Original file line number Diff line number Diff line change 2
2
Title : collections.Counter()
3
3
Subdomain : Collections
4
4
Domain : Python
5
- Author : Ahmedur Rahman Shovon
5
+ Author : Md Samshad Rahman
6
6
Created : 15 July 2016
7
+ Updated : 26 November 2024
7
8
Problem : https://www.hackerrank.com/challenges/collections-counter/problem
8
9
"""
10
+ import collections
11
+
12
+
13
+ if __name__ == '__main__' :
14
+ total_shoes = int (input ())
15
+ shoe_sizes = list (map (int , input ().split ()))
16
+ inventory = collections .Counter (shoe_sizes )
17
+
18
+ total_customers = int (input ())
19
+ total_revenue = 0
20
+
21
+ for _ in range (total_customers ):
22
+ size , price = map (int , input ().split ())
23
+ if inventory .get (size ) and inventory [size ] > 0 :
24
+ total_revenue += price
25
+ inventory [size ] -= 1
26
+
27
+ print (total_revenue )
28
+
9
29
10
- x = int (input ())
11
- shoe_size = list (map (int , input ().split ()))
12
- n = int (input ())
13
- sell = 0
14
- for _ in range (n ):
15
- s , p = map (int , input ().split ())
16
- if s in shoe_size :
17
- sell = sell + p
18
- shoe_size .remove (s )
19
- print (sell )
You can’t perform that action at this time.
0 commit comments