8. Buy a hundred chickens for a hundred dollars
Title description
In the fifth century BC, the ancient Chinese mathematician Zhang Qiujian put forward the "Hundred Chicken Problem" in his book "Mathematics": a chicken is worth five, a female chicken is worth three, and three chickens are worth one. Buy a hundred chickens for a hundred dollars, and ask how are the chickens, the mothers, and the chicks?
Detailed Description:
Interface Description
prototype:
int GetResult(vector &list)
Input parameters:
无
Output parameters (the memory area pointed to by the pointer is guaranteed to be valid):
list A list of combinations of chickens, females, and chicks
return value:
-1 failed
0 success
Example
enter
1
Output
0 25 75
4 18 78
8 11 81
12 4 84
analysis
1. Simple math problem is to use the largest to buy
2. Then determine whether the conditions are met
Code
public class Main {
public static void main(String[] args) {
for(int i=0;i<=20;i++) {
for(int j=0;j<=33;j++) {
for(int k=0;k<=300;k=k+3) {
if(i*5+j*3+(k/3)==100) {
if(i+j+k==100) {
System.out.println(i+" "+j+" "+k);
}
}
}
}
}
}
}