5位运动员参加了10米台跳水比赛,有人让他们预测比赛结果
A选手说:B第一,我第三。
B选手说:我第二,E第四。
C选手说:我第一,D第二。
D选手说:C最后,我第三。
E选手说:我第四,A第一。
比赛结束后,每位选手都说对了一半,请编程确定比赛的名次。#include <stdio.h>
#include <windows.h>
int main()
{
int A, B, C, D, E;
for (A=1; A<=5; A++)
for (B=1; B<=5; B++)
for (C=1; C<=5; C++)
for (D=1; D<=5; D++)
for (E=1; E<=5; E++)
{
if ((1 == B) + (3 == A) == 1 &&
(2 == B) + (4 == E) == 1 &&
(1 == C) + (2 == D) == 1 &&
(5 == C) + (3 == D) == 1 &&
(4 == E) + (1 == A) == 1)
{
int val = 0;
int flag = 1;
val |= (1 << (A - 1));
val |= (1 << (B - 1));
val |= (1 << (C - 1));
val |= (1 << (D - 1));
val |= (1 << (E - 1));
while (val)
{
if (val % 2 == 0)
{
flag = 0;
}
val /= 2;
}
if (flag == 1 )
{
printf("A=%d B=%d C=%d D=%d E=%d\n", A, B, C, D, E);
}
}
}
system("pause");
return 0;
}
#include <stdio.h>
#include <windows.h>
int main()
{
int A, B, C, D, E;
for (A=1; A<=5; A++)
for (B=1; B<=5; B++)
for (C=1; C<=5; C++)
for (D=1; D<=5; D++)
for (E=1; E<=5; E++)
{
if ((1 == B) + (3 == A) == 1 &&
(2 == B) + (4 == E) == 1 &&
(1 == C) + (2 == D) == 1 &&
(5 == C) + (3 == D) == 1 &&
(4 == E) + (1 == A) == 1)
{
int val = 0;
int flag = 1;
val |= (1 << (A - 1));
val |= (1 << (B - 1));
val |= (1 << (C - 1));
val |= (1 << (D - 1));
val |= (1 << (E - 1));
while (val)
{
if (val % 2 == 0)
{
flag = 0;
}
val /= 2;
}
if (flag == 1 )
{
printf("A=%d B=%d C=%d D=%d E=%d\n", A, B, C, D, E);
}
}
}
system("pause");
return 0;
}