题解 | #百钱买百鸡问题#
百钱买百鸡问题
https://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
import java.util.Scanner; /** * HJ72 百钱买百鸡问题 * 利用公式计算: * x+y+z = 100; * 5x + 3y +z/3 =100 * z用x和y替换后得出: * 7x+4y=100 */ public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int n = scanner.nextInt(); int x, y, z; for (x = 0; x <= 100 / 7; x++) { int i = x * 7; int j = 100 - x * 7; if (j % 4 == 0) { System.out.println(x + " " + j / 4 + " " + (100 - x - j / 4)); } } } } }