【C++】编写百鸡百元程序代码

//雄鸡为7元/只,母鸡为5元/只,小鸡为1元/3只,如果100元 100只鸡中包含 雄鸡,母鸡,小鸡。各多少只呢?
#include 
using namespace std;  
int main (){
	//雄鸡最高耗用金额为 100-5-1 =94元,取7的倍数,得91元,雄鸡数的范围为1~13只
	//雄鸡数
	for(int cock=1;cock<=13;++cock)
	//母鸡最高耗用金额为100-7-1=92元,取92%5~18,母鸡数的范围为1~18只
	for(int hen=1;hen<=18;++hen)
	
	//小鸡最高耗用金额为100-7-5 = 88元,去88%1*3=264只,由于限制只能买<=98只,但是 小鸡只能为3的倍数所以 只有96只;
	for(int chick=1;chick<=96;++chick){
		
		if(7*cock+hen*5+chick/3-100) continue;
		if(cock+hen+chick-100) continue;
		if(chick%3) continue;
			
		cout << "Cock:"<

输出:

【C++】编写百鸡百元程序代码_第1张图片

你可能感兴趣的:(C++基础代码)