counter exercise
This commit is contained in:
parent
31b9f177d7
commit
766d118785
|
|
@ -1,2 +1,5 @@
|
|||
.vscode/
|
||||
*.exe
|
||||
*.exe
|
||||
*.inp
|
||||
*.oac
|
||||
*.out
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
# Python > Collections > collections.Counter()
|
||||
# Use a counter to sum the amount of money earned by the shoe shop owner.
|
||||
#
|
||||
# https://www.hackerrank.com/challenges/collections-counter/problem
|
||||
|
||||
from collections import Counter
|
||||
|
||||
def calc_shoes():
|
||||
input() # no. of shoes not used
|
||||
shoes = Counter(input().split())
|
||||
|
||||
money = 0
|
||||
for _ in range(int(input())):
|
||||
shoe, price = input().split()
|
||||
if shoe in shoes:
|
||||
shoes[shoe] -= 1
|
||||
if shoes[shoe] >= 0:
|
||||
money += int(price)
|
||||
|
||||
return money
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(calc_shoes())
|
||||
Loading…
Reference in New Issue