百钱买百鸡问题

链接:https://www.nowcoder.com/questionTerminal/74c493f094304ea2bda37d0dc40dc85b
来源:牛客网

公元前五世纪,我国古代数学家张丘建在《算经》一书中提出了“百鸡问题”:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?
示例1
输入
1
输出
0 25 75
4 18 78
8 11 81
12 4 84

 public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int d = in.nextInt();
            for (int a = 0; a < 100 / 5; a++) {
                for (int b = 0; b < 100 / 3; b++) {
                    for (int c = 0; c < 100; c += 3) {
                        if ((5 * a + 3 * b + c / 3 == 100) && a + b + c == 100) {
                            System.out.println(a + " " + b + " " + c);
                        }
                    }
                }
            }
            in.close();
        }
    }

你可能感兴趣的:(OJ题)