Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Uses python3
- import sys
- # list and not set because we want to ordered with max and iterate so sequenced
- coins = [1, 5, 10]
- res = 0
- def get_change(m):
- coins.sort()
- global res
- while len(coins) > 0:
- while m >= coins[-1]: # while the amount is still greater than the biggest coin denomination
- m -= max(coins)
- res += 1
- coins.pop() # then we remove the largest coin denomination and iterate over
- get_change(m)
- return res
- if __name__ == '__main__':
- m = int(sys.stdin.read())
- print(get_change(m))
Add Comment
Please, Sign In to add comment