A hundred money to buy a hundred chicken C++ optimized version

A hundred money to buy a hundred chicken C++ optimized version

The third optimization is to eliminate the equation to ensure the integer characteristic of the number of chickens.

#include<iostream>
using namespace std;

int main(){
    
    
	system("pause");
	//方案一
	for (int cock = 0; cock <100; cock++)
	{
    
    
		for (int hen = 0; hen<100; hen++)
		{
    
    
			for (int chick = 0; chick <100; chick+=3)
			{
    
    
				if ((cock+hen+chick==100)&&(5*cock+3*hen+chick/3==100))
				{
    
    
					cout<<cock<<"," <<hen<<","<<chick<< endl;
				}
			}
		}
	}

	//方案二
	for (int cock = 0; cock < 20; cock++)
	{
    
    
		for (int hen = 0; hen<33; hen++)
		{
    
    
			for (int chick = 0; chick <100; chick+=3)
			{
    
    
				if ((cock + hen + chick == 100) && (5 * cock + 3 * hen + chick / 3 == 100))
				{
    
    
					cout << cock << "," << hen << "," << chick << endl;
				}
			}
		}
	}

	//方案三

	for (int cock1 = 0; cock1 < 16; cock1+=4)
	{
    
    
		int hen1 = 25 - 7 * cock1 / 4;
		int chick1 = 1000 - cock1 - hen1;
		cout << cock1 << "," << hen1 << "," << chick1 << endl;
	}
	cout << endl;
	return 0;
}

Guess you like

Origin blog.csdn.net/p715306030/article/details/114299152