一道C++题目,求解答

2024-11-15 03:21:59
推荐回答(1个)
回答1:

#include
using namespace std;

int main()
{
int A, B, C; //定义3个人的饭量
int As, Bs, Cs; //定义3个人说的话
int AnsA, AnsB, AnsC; //用于记录最后的答案
for (A = 1; A <= 3; A++)
for (B = 1; B <= 3; B++)
for (C = 1; C <= 3; C++)
{
As = (B>A) + (C==A); //A讲的话
Bs = (A>B) + (A>C) ; //B讲的话
Cs = (C>B) + (B>A) ; //C讲的话
if(!(A <= B && As <= Bs || A <= C && As <= Cs ||
B <= A && Bs <= As || B <= C && Bs <= Cs ||
C <= A && Cs <= As || C <= B && Cs <= Bs))
//如果不存在一个人饭量比另一个人小,说对的话也不比另一个人多,则记录下这时的解
{
AnsA = A;
AnsB = B;
AnsC = C;
}
}
//输出部分省略
return 0;
}