那些年我们写过的作业(四)
作业四:4. 有人想将手中一张面值100元的人民币换成5元、1元、0.5元面值的零钱100张,以上三种面值的零钱至少有一张,问共有几种换法。请编程实现
package com.stx;
//4. 有人想将手中一张面值100元的人民币换成5元、1元、0.5元面值的零钱100张,以上三种面值的零钱至少有一张,问共有几种换法。请编程实现。
public class p4 {
public static void main(String[] args){
//赋值
float max=100;
float wuyuan=5;
float yiyuan=1;
float wumao =0.5f;
int r5,r1,r05;//张数
int n =0;//次数
for (r5=1;r5<(100/5);r5++){
for(r1=1;r1<(100-r5);r1++){
r05=100-r5-r1;//一共100张
if(r5*wuyuan+r1*yiyuan+r05*wumao==max&&r5+r1+r05==100){
n++;
}
}
}System.out.println("一共有"+n+"种方法");
}
}