题解 | HJ72#百钱买百鸡问题#
百钱买百鸡问题
https://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { scanner.next(); //HJ72 百钱买百鸡 公鸡 母鸡 小鸡 //5x+3y+1/3z=100 x+y+z=100 int y; int x; int z; for (x = 0; x <= 100; x++) { for (y = 0; y <= 100; y++) { if ((100 - x - y) % 3 == 0) { if (5 * x + (3 * y) + (100 - x - y) / 3 == 100 && x + y <= 100) { z = 100 - y - x; System.out.print(x + " " + y + " " + z); System.out.println(); } } } } } } }