// 1045_百雞問題.cpp : 定義控制臺應用程序的入口點。//1045:百雞問題//時間限制:1 秒內存限制:32 兆特殊判題:否提交:10137解決:4453//題目描述://用小于等于n元去買100只雞,大雞5元/只,小雞3元/只,還有1/3元每只的一種小雞,分別記為x只,y只,z只。編程求解x,y,z所有可能解。//輸入://測試數據有多組,輸入n。//輸出://對于每組輸入,請輸出x,y,z所有可行解,按照x,y,z依次增大的順序輸出。//樣例輸入://40//樣例輸出://x=0,y=0,z=100//x=0,y=1,z=99//x=0,y=2,z=98//x=1,y=0,z=99//來源://2009年哈爾濱工業大學計算機研究生機試真題#include "stdafx.h"#include "stdio.h"#include "iostream"#include "string.h"#include "string"using namespace std;int main(){ int n; int x,y,z; while(cin>>n){ for(int x = 0;x<=100;x++) for(int y = 0;y<=100;y++){ z = 100-x-y; if(5*x+3*y+1.0/3*z<=n) cout<<"x="<<x<<","<<"y="<<y<<","<<"z="<<z<<endl; } } return 0;}