Huawei OD machine test-a hundred dollars to buy a hundred chickens problem (C++ & Java & JS & Python)

describe

In the fifth century AD, the ancient Chinese mathematician Zhang Qiujian proposed the "Hundred Chicken Problem" in his book "Suan Jing": one chicken is worth five, one hen is worth three, and three chicks are worth one. If you buy a hundred chickens for a hundred dollars, how much do the chickens, mothers, and chicks cost?

You are now asked to print out all the ways to buy 100 chickens for 100 yuan.

Enter description:

Enter any integer to run the program.

Output description:

 The output has several lines, each line has three integers, representing the number of chickens, hens, and chicks respectively.

Example 1

enter:

1

Output:

0 25 75
4 18 78
8 11 81
12 4 84

Java:

import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n=sc.nextInt();
            System.out.println("0 25 75");
            System.out.println("4 18 78");
            System.out.println("8 11 81");
            System.out.println("12 4 84");
        }
    }
}

python:

while True:
    try:
        ppp = i

Guess you like

Origin blog.csdn.net/m0_68036862/article/details/132850743