贪心算法--找零问题

博客地址:https://www.cnblogs.com/zylyehuo/

# -*- coding: utf-8 -*-

t = [100, 50, 20, 5]


def change(t, n):
    m = [0 for _ in range(len(t))]  # m 为各面额纸币的张数
    for i, money in enumerate(t):
        m[i] = n // money
        n = n % money  # n 为找零金额
    return m, n


print(change(t, 376))

posted @ 2023-08-18 21:28  zylyehuo  阅读(9)  评论(0编辑  收藏  举报