A criminal Investigation Brigade has analyzed a mystery involving six suspects:
(1) A, B at least one person committed the crime; (2) A, E, F Three have at least two persons involved in the crime, (3) A, D cannot be accomplices, (4) B, C or both, or is unrelated to the case, (5) C, D and only one person, (6) If D is not involved in the crime, then E may not participate in the crime. The brute force method is used to design an algorithm to find out the perpetrator.
1#include <iostream>2#include <cstdio>3 using namespacestd;4 5 intMain ()6 {7 inta,b,c,d,e,f,g;8 for(a=0; a<2; a++)9 for(b=0; b<2; b++)Ten for(c=0; c<2; C++) One for(d=0;D <2;D + +) A for(e=0; e<2; e++) - for(f=0; f<2; f++) - for(g=0; g<2; g++) the if((a+b>0) && (a+e+f>=2) && (a+d<2)
&& ((b+c) = =2|| (b+c) = =0) && (c+d==1) && (d==0&&e==0|| d==1)){ -Puts (a==1?"Crime":"no crime ."); -Puts (b==1?"Crime":"no crime ."); -Puts (c==1?"Crime":"no crime ."); +Puts (d==1?"Crime":"no crime ."); -Puts (e==1?"Crime":"no crime ."); +Puts (f==1?"Crime":"no crime ."); Aprintf"\ n"); at } - return 0; -}
Find the prisoner-Brute force method (algorithm)