贪心算法找零问题
找零问题:假设商店老板需要找零n元钱,钱币的面额有:100元、50元、20元、5元、1元,如何找零使得所需钱币的数量最少?
# greedy algorithm money = [100,50,20,5,1] def change_money(x): change = [0,0,0,0,0] for i,m in enumerate(money): change[i] = x // money[i] x = x % money[i] if x > 0: print("还剩%s" % x) return change print(change_money(356.2))