day20.2
谁能横刀立马,唯我飞牛大将军!
#猜排名代码
5位运动员参加了10米台跳水比赛,有人让他们预测比赛结果:
A选手说:B第二,我第三;
B选手说:我第二,E第四;
C选手说:我第一,D第二;
D选手说:C最后,我第三;
E选手说:我第四,A第一;
比赛结束后,每位选手都说对了一半,请编程确定比赛的名次
#include<stdio.h>
#include<windows.h>
void FoundNum()
{
int a = 1;
for (; a <= 5; a++)
{
int b = 1;
for (; b <= 5;b++)
{
int c = 1;
for (; c <= 5;c++)
{
int d = 1;
for (;d <= 5; d++)
{
int e = 1;
for (; e<= 5; e++)
{
if (((b == 2) + (a == 3)) == 1 && \
((b == 2) + (e == 4)) == 1 && \
((c == 1) + (d == 2)) == 1 && \
((c == 5) + (d == 3)) == 1 && \
((e == 4) + (a == 1)) == 1)
{
unsigned char flag = 0;
flag |= (1 << (a - 1));
flag |= (1 << (b - 1));
flag |= (1 << (c - 1));
flag |= (1 << (d - 1));
flag |= (1 << (e- 1));
/*
不要求并列
while (flag){
if (!(flag & 1))
{
break;
}
flag >>= 1;
}
if (!flag)
{
printf("A:%d B:%d C:%d D:%d E:%d \n", a, b, c, d, e);
}*/
//要求并列
if (flag == 0x1F)
{
printf("A:%d B:%d C:%d D:%d E:%d \n", a, b, c, d, e);
}
}
}
}
}
}
}
}
int main()
{
FoundNum();
system("pause");
return 0;
}