题目描述
用小于等于n元去买100只鸡,大鸡5元/只,小鸡3元/只,还有1/3元每只的一种小鸡,分别记为x只,y只,z只。编程求解x,y,z所有可能解。
输入
测试数据有多组,输入n。
输出
对于每组输入,请输出x,y,z所有可行解,按照x,y,z依次增大的顺序输出。
样例输入 Copy
45
样例输出 Copy
x=0,y=0,z=100 x=0,y=1,z=99 x=0,y=2,z=98 x=0,y=3,z=97 x=0,y=4,z=96 x=1,y=0,z=99 x=1,y=1,z=98 x=1,y=2,z=97 x=2,y=0,z=98
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
using namespace std;
int main(int argc, char** argv) {
int n;
while(cin >> n){
int x, y, z;
for(int x = 0; x <= 100; x++){
for(int y = 0; y <= 100 - x; y++){//这里y和x和小于等于100
int z = 100 - x - y;
if(5 *3* x + 3 *3*y + z <= n*3){
printf("x=%d,y=%d,z=%d\n", x, y, z);
}
}
}
}
return 0;
}