省赛选拔-A 警察抓小偷

警察抓了 A、B、C、D、E、F、G 七名罪犯,其中四名是小偷,审讯的时候:
因此有四人说谎,警察想要找出小偷是哪些。
A说:“我不是小偷。” x !=0
B说:“E 是小偷。” x = 4
C说:“小偷肯定是 D。” x = 3
D说:“C 是在冤枉人。” x != 3
E说:“小偷不是A和F中的一人。” !(x=0||x=5)
F说:“E在撒谎。” x!=0&&x!=5
G说:“小偷不是D,小偷一定是C。” x=2
输出有四行:
the thief is M
the thief is N
the thief is O
the thief is P
其中MNOP代表小偷

模拟题,非真即假,用布尔类型枚举即可。
题目不严谨,看看即可。

#include<iostream>
using namespace std;
int main()
{
	int cnt=0;
	for(int x=0;x<7;x++)
	{
		//cout<<cnt++<<endl;
		int a=(x!=0)?1:0;
		int b=(x==4)?1:0;
		int c=(x==3)?1:0;
		int d=(x!=3)?1:0;
		int e=!(x==0||x==5)?1:0;
		int f=(!e)?1:0;
		int g=((x!=3&&x==2))?1:0;
		if((a+b+c+d+e+f+g)==3)
		{
			cout<<"the thief is "<<char('A'+x)<<endl;
		}
	}
	return 0;
}
posted @ 2019-05-04 17:40  一块钱的争论  阅读(257)  评论(4编辑  收藏  举报