分析:

对A,B,C三人说的话的真假变量a,b,c表示,a,b,c的取值为1或0

按照题意:存在如下逻辑关系:

(1)若a = 1, 则 b = 0;

(2)若a = 0, 则 b = 1;

(3)若b = 1, 则 c = 0;

(4)若b = 0, 则 c = 1;

(5)若c = 1, 则 a+b = 0;

(6)若c = 0, 则 a+b != 0;

总结关系式为:

(a==1)&&(b==0)  || (a==0)&&(b==1)  || (b==1)&&(c==0)  ||  (b==0)&&(c==1)  ||  (c==1)&&(a+b==0)  || (c==0)&&(a+b != 0)

化简后为(a && !b || !a && b) && (b && !c || !b && c) && (c && (a + b == 0) || !c && (a + b != 0) )

所以凡是不满足以上条件的答案组合就不是正确答案,可用穷举法检测所有解空间

穷举法源码:

   1: #include <stdio.h>
   2:  
   3: int main()
   4: {
   5:     int a, b, c;
   6:  
   7:     for(a = 0; a <= 1; a++)
   8:         for(b = 0; b <= 1; b++)
   9:             for(c = 0; c <= 1; c++)
  10:                 if((a && !b || !a && b) && (b && !c || !b && c) && (c && a + b == 0 || !c && a + b != 0))
  11:                 {
  12:                     printf("甲 told a %s\n", a ? "truth" : "lie");
  13:                     printf("乙 told a %s\n", b ? "truth" : "lie");
  14:                     printf("丙 told a %s\n", c ? "truth" : "lie");
  15:                 }
  16:  
  17:     return 0;
  18: }