题解 | #百钱买百鸡问题#
百钱买百鸡问题
http://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
in.nextInt();
int x = 0,y = 0,z = 0;
// 5x + 3y + z/3 = 100
// x + y + z = 100
// 3y + 7z = 600
// i表示小鸡数量,必须是3的倍,不然钱不是整数
for (int i = 0; i < 100; i+=3) {
z = i;
y = (600 - 7*z)/3;
x = 100 - z - y;
if (y < 0 || x < 0){
continue;
}
System.out.println(x + " " + y + " " + z);
}
}
}