标签:init ble style blog 顺序 add += close hit
将一笔零钱换成5分、2分和1分的硬币,要求每种硬币至少有一枚,有几种不同的换法?
输入在一行中给出待换的零钱数额。
要求按5分、2分和1分硬币的数量依次从大到小的顺序,输出各种换法。每行输出一种换法,格式为:“fen5:5分硬币数量, fen2:2分硬币数量, fen1:1分硬币数量, total:硬币总数量”。最后一行输出“count = 换法个数”。
13
fen5:2, fen2:1, fen1:1, total:4
fen5:1, fen2:3, fen1:2, total:6
fen5:1, fen2:2, fen1:4, total:7
fen5:1, fen2:1, fen1:6, total:8
count = 4
代码如下:
#!/usr/bin/python # -*- coding: utf-8 -*- n = int(input()) a,b,c = 5,2,1 count = 0 for fen5 in range(n//5,0,-1): for fen2 in range(n//2,0,-1): for fen1 in range(n,0,-1): if a*fen5 +b*fen2 + c*fen1 == n : count += 1 print("fen5:{:d}, fen2:{:d}, fen1:{:d}, total:{:d}".format(fen5,fen2,fen1,fen5+fen2+fen1)) print("count =",count)
这个程序不难,参考以前的进行了修正。
原文链接:https://www.cnblogs.com/Renqy/p/12740786.html
读书和健身总有一个在路上
标签:init ble style blog 顺序 add += close hit
原文地址:https://www.cnblogs.com/Renqy/p/12780493.html