A homicide occurred in a certain place in Japan, and it was often determined through investigation that the murderer must be one of the four suspects.
Here are the confessions of the four suspects:
A said: Not me.
B said: It is C.
C said: Yes D.
D said: C is talking nonsense.
It is known that 3 people told the truth and 1 person told the lie.
Based on this information, please write a program to determine who the murderer is?
To solve this problem, we must first draw a graph analysis:
Write a program from the analysis results:
#include<stdio.h>
int main()
{
char k = 0; // 设定k是凶手
for (k = 'A'; k <= 'D'; k++)
{
//printf("%c\n", k);
//如果((k不是A)+(k是C)+(k是D)+(k不是D)的结果等于3)----就是三个真话,一个假话
if (((k != 'A') + (k == 'C') + (k == 'D') + (k != 'D')) == 3)
{
printf("凶手是:%c\n", k); // 满足条件的k就是凶手了
}
}
return 0;
}
The following is the result of running: