Criminal Investigation Brigade analysis of the six suspects involved in a mystery, and compile a program, find out the perpetrators

Somewhere Criminal Investigation Brigade of the six suspects involved in a mystery for analysis: (1) A, B at least one person committing the crime; (2) A, E, F trio at least two people involved in the crime; (3) A , D can not be accomplice; (4) B, C simultaneously or crime, or not relevant to the case; (5) C, D and only one person in the crime; (6) If D is not involved in the crime, then E can not involved in committing the crime. Design algorithm uses brute force method to find out the perpetrators.

|| represents the arithmetic sign of things to the left, and then determine whether the true, is true stopped direct output will not be running things behind, it is false to continue operation of the right judgment and then output.

&& symbols represent something to the left of the operation, and then determine whether it is true, is true of the right to continue operation and then determine the output is false stopped directly behind the output will not run things.

#include<iostream>
using namespace std;
int main()
{
	int A, B, C, D, E, F;//定义A到E六个变量,作案等于1,否则等于0
	for (A = 0; A <= 1; A += 1)
		for (B = 0; B <= 1; B += 1)
			for (C = 0; C <= 1; C += 1)
				for (D = 0; D <= 1; D += 1)
					for (E = 0; E <= 1; E += 1)
						for (F = 0; F <= 1; F += 1)
						{
								if (6 ==
									(A || B)				//A、B 至少有一人作案
									+ (!(A && D))				//A、D 不可能是同案犯
									+ ((A && E) || (A && F) || (E && F))	//A、E、F 三人中至少有两人参与作案
									+ ((B && C) || (!B && !C))		//B、C 或同时作案,或与本案无关
									+ ((C && !D) || (D && !C))		//C、D 中有且仅有一人作案
									+ (D || (!E)))//如果 D 没有参与作案,则 E 也不可能参与作案。
							{
								cout << "A " << "B " << "C " << "D " << "E " << "F " << endl;
								cout << A << " " << B << " " << C << " " << D << " " << E << " " << F << " " << endl;
							}
						}
	return 0;
}
Published 93 original articles · won praise 31 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_43866567/article/details/104769828