测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A31968. 下面Python代码用于将输入金额换成最少币种组合方案,其实现算法是( )。def findCoins(coins, Money): coins_used = [] for coin in coins: while Money >= coin: coins_used.append(coin) Money -= coin return coins_usedcoins = [100, 50, 20,…

单选题 10

题目描述

下面Python代码用于将输入金额换成最少币种组合方案,其实现算法是( )。

def findCoins(coins, Money):

coins_used = [] 

for coin in coins:

while Money >= coin: 

coins_used.append(coin)

Money -= coin

return coins_used


coins = [100, 50, 20, 10, 5, 2, 1] #货币种类,单位相同

M = int(input()) #输入换算的金额coins_needed = find_coins(coins, M)


result = [(c,coins_needed.count(c)) for c in coins] 

result = [x for x in result if x[1] > 0]

选项(单选)

上一题 下一题