题解 | #百钱买百鸡问题#,刚开始没看懂文言文哈哈
百钱买百鸡问题
http://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
import java.util.ArrayList;
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int z = 0;
int x = 0;
int y = 100 - x - z;
int nextInt = in.nextInt();
ArrayList<String> list = new ArrayList<>();
while (z <= 99){
while (x <= 100 - z){
if ((5 * x) + (3 * y) + (z/3) == 100){
list.add(x + " " + y + " " + z);
}
x += 1;
y = 100 - x - z;
}
z += 3;
x = 0;
y = 100 -x -z;
}
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
}
}