/****************************************
* File Name : reasoning.c
* Creat Data : 2015.1.26
* Author : ZY
*****************************************/
/*逻辑推理与判断*/
/*黑与白*/
/*有A,B,C,D,E五人,每人额头上都贴着一张或黑或白的纸。五人对坐,
每个人都可以看到其他额头上的纸的颜色,但都不知道自己额头上的纸
的颜色,五个人相互观察后,
A说:“我看见有三个人额头上贴的是白纸,一人额头贴的是黑纸。”
B说:“我看见其他四个人额头贴的都是黑纸。”
C说:“我看见有一人额头贴的是白纸,其他三个人额头贴的是黑纸。”
D说:“我看见四人额头上贴的都是白纸。”
E什么也没说。
现在已知额头贴黑纸的人说的是谎话,额头贴白纸的人说的都是实话,
问这五人谁的额头是贴白纸(1),谁的额头是贴黑纸(0)。
A说:a&&b+c+d+e == 3 || !a&&b+c+d+e != 3
B说:b&&a+c+d+e == 0 || !b&&a+c+d+e != 0
C说:c&&a+b+d+e == 1 || !c&&a+b+d+e != 1
D说:d&&a+b+c+e == 4 || !d&&a+b+c+e != 4*/
#include <stdio.h>
int main(void)
{
int a,b,c,d,e;
for(a = 0;a < 2;a++)
{
for(b = 0;b < 2;b++)
{
for(c = 0;c < 2;c++)
{
for(d = 0;d < 2;d++)
{
for(e = 0;e < 2;e++)
{
if((a&&b+c+d+e == 3 || !a&&b+c+d+e != 3)
&&(b&&a+c+d+e == 0 || !b&&a+c+d+e != 0)
&&(c&&a+b+d+e == 1 || !c&&a+b+d+e != 1)
&&(d&&a+b+c+e == 4 || !d&&a+b+c+e != 4))
{
printf("A is pasted a piece of %s paper on his forehead.\n",a?"white":"black");
printf("B is pasted a piece of %s paper on his forehead.\n",b?"white":"black");
printf("C is pasted a piece of %s paper on his forehead.\n",c?"white":"black");
printf("D is pasted a piece of %s paper on his forehead.\n",d?"white":"black");
printf("E is pasted a piece of %s paper on his forehead.\n",e?"white":"black");
}
}
}
}
}
}
return 0;
}
逻辑推理与判断(黑与白)
最新推荐文章于 2022-01-10 22:00:15 发布