题解 | #百钱买百鸡问题#
百钱买百鸡问题
http://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
public class Main {
public static void main(String[] args) {
/*
鸡翁:x
鸡母:y
鸡雏:z
1.x+y+z=100;
2.价格满足5x + 3Y <= 100 即可
*/
int z = 0;
for (int x = 0; x <= 100; x += 5) {//鸡翁用价
for (int y = 0; y <= 100 - x; y += 3) {//鸡母用价
z = 100 - x - y;//鸡雏用价
if (x/5 + y/3 + z*3 == 100){//满足三种鸡共百只则输出
System.out.println(x/5 + " " + y/3 + " " + z*3);
}
}
}
}
}