此题是简单的模拟:
含有刁难人的意思按照x,y,z的顺序输出,其实就是for的顺序
此题需要注意的地方是(double)z/3就对,double(z/3)就错;
AC的代码:
#include<iostream> using namespace std; int main() { int n; while(cin>>n) { int x=0,y=0,z=0; for (x=0;x<=n/5;x++) for(y=0;y<=n/3;y++) for(z=0;z<=n*3;z++) if(((double)z/3+5*x+y*3)<=n && (x+y+z==100)) cout<<"x="<<x<<","<<"y="<<y<<","<<"z="<<z<<endl; } return 0; }