C language: logical reasoning

1A, B, C, D, E five students are likely to participate in the computer competition, according to the following conditions to judge which ones (10 points)

Topic content:

 

Five students A, B, C, D, and E are likely to participate in the computer competition. Judge which ones are based on the following conditions

  People who participated in the contest:

 

   (1) When A participates, B also participates;

 

   (2) Only one person from B and C participates;

 

   (3) Both C and D participate, or neither;

 

   (4) At least one of D and E shall participate;

 

   (5) If E participates, then both A and D participate.

 

Input format:

 

without

 

Output format:

Capital letters indicate who participated, with no spaces in between.

For example, the final result is that A and D participated, then output

AD

 coding:

 

#include<stdio.h>
int main(){
	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) continue;
                      	if((B && C) || (!B && !C)) continue;
                      	if(( C && !D) || (!C && D)) continue;
                      	if (!D && !E) continue;
                      	if (E && (!A || !D)) continue;
                      	
						if(A==1)
							printf("A");
						if(B==1)
							printf("B");
						if(C==1)
							printf("C");
						if(D==1)
							printf("D");
						if(E==1)
							printf("E");
                  	}

    return 0;
}

 

2. An analysis of a suspected case involving 6 suspects by a local criminal police brigade: (10 points)

Topic content:

A local criminal police brigade analyzes a suspicious case involving 6 suspects: ( 
1) At least one of A and B committed the crime; (
2) At least two of the three A, E, and F participated in the crime;
(3) It is impossible for A and D to commit the crime is an accomplice;
⑷ B and C committed the crime at the same time, or both have nothing to do with the case;
⑸ One and only one of C and D committed the crime;
⑹ If D did not participate in the crime, then E could not participate in the crime either.
Program to find the perpetrator.

 

Input format:

 

 

Output format:

Capital letters indicate who participated, with no spaces in between.

For example, the final result is that A and D participated, then output

AD

 coding:

#include<stdio.h>  
intmain()  
{  
    int A, B, C, D, E, F ;//Define six variables from A to E, the crime is equal to 1, otherwise it is equal to 0  
    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++)  
              for(F = 0 ; F < 2 ; F++)  
	            {  
	                if(6 ==  
	                ( A || B ) //At least one of A and B committed the crime  
	                +( !(A && D) ) //A and D cannot be accomplices  
	                +( (A && E) || (A && F) || (E && F) ) //At least two of A, E, and F participated in the crime  
	                +( (B && C) || (!B && !C) ) //B, C or both commit crimes, or have nothing to do with this case  
	                +( (C && !D) || (D && !C) ) //There is only one person in C and D who committed the crime  
	                +( D||(!E)) )//If D is not involved in committing the crime, then E cannot be involved either.  
	                {  
	                    if(A==1)
							printf("A");
						if(B==1)
							printf("B");
						if(C==1)
							printf("C");
						if(D==1)
							printf("D");
						if(E==1)
							printf("E");
	                }  
	            }  
     return 0 ;  
}  

  

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324816480&siteId=291194637