题解 | #百钱买百鸡问题#
百钱买百鸡问题
http://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
if (in.hasNextInt()) { // 注意 while 处理多个 case
int n = 0;
for(int x =0;x <= 100 / 5;x++){
double y = (200 - 14 * x) / 8.0;
double z = 100 - x - y;
int yi = (int)y;
if(y == yi && y >= 0 && z >= 0){
System.out.println(x + " " + (int)y + " " + (int)z);
}
}
}
}
}
查看6道真题和解析