抵抗暴力运动
第一种:
int Chicken, Rabit;
int Head;
bool Exsit = false;
int SumFoot;
cout << "输入总个数和脚数:" << endl;
cin >> Head >> SumFoot;
if (SumFoot%2==1||Head*2>SumFoot||SumFoot>Head*4)//1.脚的总个数不可是有奇数 2.全是鸡头 Head*2<SumFoot 3.全是兔头Head*4>SumFoot
{
cout << "不存在";
return 0;
}
for (Chicken=0;Chicken<=Head;Chicken++)
{
Rabit=Head - Chicken;
if (4*Rabit+2*Chicken==SumFoot)
{
Exsit = true;
cout << "兔子:" << Rabit << "公鸡:" << Chicken;
}
}
if (!Exsit)
{
cout << "没有";
}
第二种:
int Chicken, Rabit;
int Head;
bool Exsit = false;
int SumFoot;
cout << "输入总个数和脚数:" << endl;
cin >> Head >> SumFoot;
if (SumFoot%2==1||Head*2>SumFoot||SumFoot>Head*4)//1.脚的总个数不可是有奇数 2.全是鸡头 Head*2<SumFoot 3.全是兔头Head*4>SumFoot
{
cout << "不存在";
return 0;
}
Rabit = (SumFoot - Head * 2) / 2;
Chicken = Head - Rabit;
cout << "兔子:" << Rabit << "鸡:" << Chicken;