jules0707

change_money

Jun 19th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # Uses python3
  2. import sys
  3.  
  4. # list and not set because we want to ordered with max and iterate so sequenced
  5. coins = [1, 5, 10]
  6. res = 0
  7.  
  8.  
  9. def get_change(m):
  10.     coins.sort()
  11.     global res
  12.  
  13.     while len(coins) > 0:
  14.         while m >= coins[-1]: # while the amount is still greater than the biggest coin denomination
  15.             m -= max(coins)
  16.             res += 1
  17.         coins.pop()           # then we remove the largest coin denomination and iterate over
  18.         get_change(m)
  19.     return res
  20.  
  21.  
  22. if __name__ == '__main__':
  23.     m = int(sys.stdin.read())
  24.     print(get_change(m))
Add Comment
Please, Sign In to add comment