-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollectionsCounter.py
executable file
·45 lines (37 loc) · 1.1 KB
/
collectionsCounter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/env python3
"""
Counter - a containter that stores elements as dictionary keys,
and their counts are stored as dictionary values.
INPUT:
X, number of shoes
shoe_size_array, list of all shoe sizes in shop
N, number of customers
next N lines two space separated values:
s p
shoe size price of shoe
OUTPUT:
Amount of money earned
"""
import collections
if __name__ == '__main__':
"""
Read the number of shoes, the size list and the number
of customers.
Then confirm size list has correct number of items.
Then convert size list into a collection.
For each customer read the size and price
if size in stock add price to money earned
and remove from inventory.
"""
X = int(input())
size_list = list(map(float, input().split()))
N = int(input())
assert X == len(size_list)
inventory = collections.Counter(size_list)
money = 0.0
for i in range(N):
s, p = map(float, input().split())
if inventory.get(s, 0) > 0:
money += p
inventory[s] -= 1
print("{:.0f}".format(round(money)))