00002 用一元钱兑换一分两分五分的硬币,一分两分五分每种至少一枚,共有多少种组合方式,编程实现

来源:互联网 发布:淘宝转微信链接要钱么 编辑:程序博客网 时间:2024/06/03 01:46
/** *  * 长城信息笔试2011.11.24 * 题目:用一元钱兑换一分两分五分的硬币,一分两分五分每种至少一枚,共有多少种组合方式,编程实现 * @author zs  *  */public class Test {public static void main(String[] args){int one,two,five,sum;int count=0;for(one=1;one<100;one++)for(two=1;two<50;two++)for(five=1;five<20;five++){sum = one+2*two+5*five;if (sum == 100) {System.out.println(one+" "+two+" "+five);count++;}}System.out.println("共有"+count+"种组合");}}

原创粉丝点击