题解 | #百钱买百鸡问题#
百钱买百鸡问题
https://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 的区别 while (in.hasNextInt()) { // 注意 while 处理多个 case int a = in.nextInt(); for (int x = 0; x < 20; x++) { for (int y = 0; y <= 34; y++) { for (int z = 0; z < 100; z++) { if ((5 * x + 3 * y + z / 3) == 100 && (x + y + z) == 100&&z%3==0) { System.out.println(x + " " + y+" " + z); } } } } } } }
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 a = in.nextInt(); for (int x = 0; x < 20; x++) { for (int y = 0; y <= 34; y++) { if ((7* x + 4 * y ) == 100 ) { System.out.println(x + " " + y+" " + (100-x-y)); } } } } } }