Share a logic problem. I can't do it at a glance

1. The answer to this question is
 A.A B.B C.C D.D
2. The answer to question 5 is
 A.C B.D C.A D.B 
3. Which of the following is different from the other three
3. B. 6. C. 2. D. 4
4. Which two of the following questions have the same answer
A. questions 1 and 5 B. questions 2 and 7 C. questions 1 and 9 D. questions 6 and 10
5. Which of the following questions has the same answer
8. B. 4. C. 9. D. 7
6. Which two of the following questions have the same answers as question 8
A. questions 2 and 4 B. questions 1 and 6 C. questions 3 and 10 D. questions 5 and 9
7. In the ten questions, the letter with the least number of choices is
 A.C B.B C.A D.D
8. Which of the following is not adjacent to the first in the alphabet
7. B. 5. C. 2. D. 10
9. If it is known that "the answers of question 1 and 6 are the same" and "the answers of question X and 5 are the same", then x is
6 B 10 C 2 D 9
10. In the ten questions, the difference between the most and the least of the four letters of ABCD is
 A.3 B.2 C.4 D.1

Let's look at the code:

#include <stdio.h>
#include <math.h>
/*
 * 
 * 1.The answer to this question is
 * A.A B.B C.C D.D
 * 2.The answer to question 5 is
 * A.C B.D C.A D.B 
 * 3.Which of the following is different from the other three
 * A.3. B. 6. C. 2. D. 4
 * 4.Which two of the following questions have the same answer
 * A.1,5 B. 2,7 C. 1,9 D. 6,10
 * 5.Which of the following questions has the same answer as this one
 * A.8. B. 4. C. 9. D. 7
 * 6.Which two of the following questions have the same answer as question 8
 * A.2,4 B. 1,6 C. 3,10 D. 5,9
 * 7.Among the ten questions, the letter with the least number of choices is
 * A.C B.B C.A D.D
 * 8.Which of the following is not adjacent to the first in the alphabet
 * A.Question 7 B. 5 C. 2 D. 10
 * 9.It is known that "the answer of question 1 is the same as that of question 6" and "the answer of question X is the same as that of question 5". Then X is
 * A.6. B. 10. C. 2. D. 9
 * 10.In the ten questions, the difference between the most and the least of the four letters of ABCD is
 * A.3 B.2 C.4 D.1
 * 
 * */

int MinTimes(int a[],int n)
{
	int i,abcd[4]={0};
	for(i=0;i<n;i++) abcd[a[1+i]]++;

	int min=abcd[0],j=0;
	for(i=0;i<4;i++)
	{
		if(min>abcd[i]) {min=abcd[i]; j=i;}
	}
	return j;
}

int main(int argc, char* argv[])
{ 
	int i;
	int a[11];
	for(a[1]=0;a[1]<4;a[1]++)
		for(a[2]=0;a[2]<4;a[2]++)
			for(a[3]=0;a[3]<4;a[3]++)
				for(a[4]=0;a[4]<4;a[4]++)
					for(a[5]=0;a[5]<4;a[5]++)
						for(a[6]=0;a[6]<4;a[6]++)
							for(a[7]=0;a[7]<4;a[7]++)
								for(a[8]=0;a[8]<4;a[8]++)
									for(a[9]=0;a[9]<4;a[9]++)
										for(a[10]=0;a[10]<4;a[10]++)
	{ 
		// 2. The answer to question 5 is A.C B.D C.A D.B 
		if(a[2]==0 && a[5]==2 ) {;} 
		else if (a[2]==1 && a[5]==3){;} 
		else if (a[2]==2 && a[5]==0){;}
		else if (a[2]==3 && a[5]==1){;} 
		else continue;//Next candidate

		//3. Which of the following is different from the other three A. question 3 B. question 6 C. question 2 D. question 4
		if(a[3]==0 && a[3]!=a[6] && a[6]==a[2] && a[2]==a[4]) {;}
		else if(a[3]==1 && a[6]!=a[3] && a[3]==a[2] && a[2]==a[4]) {;}
		else if(a[3]==2 && a[2]!=a[6] && a[6]==a[3] && a[3]==a[4]) {;}
		else if(a[3]==3 && a[4]!=a[6] && a[6]==a[2] && a[2]==a[3] ){;}
		else continue;

		//4. Which two of the following questions have the same answer A. questions 1 and 5 B. questions 2 and 7 C. questions 1 and 9 D. questions 6 and 10
		if(a[4]==0 && a[1]==a[5]) {;}
		else if(a[4]==1 && a[2]==a[7]) {;}
		else if(a[4]==2 && a[1]==a[9]) {;}
		else if(a[4]==3 && a[6]==a[10]) {;}
		else continue;

		//5. Which of the following questions has the same answer as this one A. question 8 B. question 4 C. question 9 D. question 7

		if(a[5]==0 && a[8]==a[5]) {;}
		else if(a[5]==1 && a[4]==a[5]) {;}
		else if(a[5]==2 && a[9]==a[5]) {;}
		else if(a[5]==3 && a[7]==a[5]) {;}
		else continue;

		//6. Which two of the following questions have the same answers as question 8 A. 2, 4 B. 1, 6 C. 3, 10 D. 5, 9
		if(a[6]==0 && a[8]==a[2] && a[8]==a[4] ) {;}
		else if(a[6]==1 && a[8]==a[1] && a[8]==a[6]) {;}
		else if(a[6]==2 && a[8]==a[3] && a[8]==a[10]) {;}
		else if(a[6]==3 && a[8]==a[5] && a[8]==a[9]) {;}
		else continue;

		//8. Which of the following is not adjacent to the first in the alphabet A. 7 B. 5 C. 2 D. 10
		if(a[8]==0 && (abs(a[7]-a[1])!=1) && (abs(a[5]-a[1])==1) && (abs(a[2]-a[1])==1) && (abs(a[10]-a[1])==1) ) {;}
		else if(a[8]==1 && (abs(a[5]-a[1])!=1) && (abs(a[7]-a[1])==1) && (abs(a[2]-a[1])==1) && (abs(a[10]-a[1])==1) ) {;}
		else if(a[8]==2 && (abs(a[2]-a[1])!=1) && (abs(a[7]-a[1])==1) && (abs(a[5]-a[1])==1) && (abs(a[10]-a[1])==1) ) {;}
		else if(a[8]==3 && (abs(a[10]-a[1])!=1) && (abs(a[7]-a[1])==1) && (abs(a[5]-a[1])==1) && (abs(a[2]-a[1])==1) ) {;}
		else continue;

		//9. It is known that "the answer of question 1 is the same as that of question 6" and "the answer of question X is the same as that of question 5" are true and false. Then X is A. question 6 B. question 10 C. question 2 D. question 9
		if(a[9]==0 && ((a[1]==a[6]) ^ (a[6]==a[5] ) ) ) {;}
		else if(a[9]==1 && ((a[1]==a[6]) ^ (a[10]==a[5] ) ) ) {;}
		else if(a[9]==2 && ((a[1]==a[6]) ^ (a[2]==a[5] ) ) ) {;}
		else if(a[9]==3 && ((a[1]==a[6]) ^ (a[9]==a[5] ) ) ) {;}
		else continue;
		//7. In the ten questions, the letter with the least number of choices is 
		if(a[7]==0 && MinTimes(a,10)==2){;}
		else if(a[7]==1 && MinTimes(a,10)==1){;}
		else if(a[7]==2 && MinTimes(a,10)==0){;}
		else if(a[7]==3 && MinTimes(a,10)==3){;}
		else continue;

		//10. no treatment


		printf("The answer to this question is:");

		for(i=1;i<=10;i++) printf(" %c",a[i]+'a');
	}
	printf("\n");
	return 0;
}

See the output:

The answer to this question is: bcaacacdadba

Posted by daveoffy on Mon, 30 Dec 2019 09:57:22 -0800