diff --git a/.gitignore b/.gitignore index 9b79cfb..5ce5fd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .vscode/ -*.exe \ No newline at end of file +*.exe +*.inp +*.oac +*.out diff --git a/Chapter 1 Arrays and strings/hackerrank/counter.py b/Chapter 1 Arrays and strings/hackerrank/counter.py new file mode 100644 index 0000000..5e84b22 --- /dev/null +++ b/Chapter 1 Arrays and strings/hackerrank/counter.py @@ -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())