此是草稿,有值得优化的地方,如从公鸡先循环再母鸡再小鸡这样可以提高效率,且有输出后也可优化为公鸡++母鸡小鸡初始化。
void 百元百鸡()
{//缘由https://ask.csdn.net/questions/7434093?spm=1005.2025.3001.5141
int xj = 1, mj = 1, gj = 1, y = 100;
while (y)
{
if (xj * 3 + mj + gj == y && xj + mj * 3 + gj * 5 == y)
{
std::cout << (xj * 3) << std::ends << mj << std::ends << gj << std::ends;
std::cout << xj << std::ends << (mj * 3) << std::ends << (gj * 5) << std::endl;
++xj;
gj = mj = 1;
}
else
{
if (++gj > y - mj - xj)
{
gj = 1;
if (++mj > y - gj - xj)
{
++xj;
mj = 1;
}
}
}
if (xj >= y)y = 0;
}
}
void 百元百鸡()
{//缘由https://ask.csdn.net/questions/7434093?spm=1005.2025.3001.5141
int xj = 1, mj = 1, gj = 1, y = 100;
while (y)
{
if (xj * 3 + mj + gj == y && xj + mj * 3 + gj * 5 == y)
{
std::cout << (xj * 3) << std::ends << mj << std::ends << gj << std::ends;
std::cout << xj << std::ends << (mj * 3) << std::ends << (gj * 5) << std::endl;
++xj;
gj = mj = 1;
}
else
{
if (++mj >= 34)
{
mj = 1;
if (++gj >= 20)
{
++xj;
gj = 1;
}
}
}
if (xj >= y)y = 0;
}
}