谁在说谎

来源:互联网 发布:linux修改dns 编辑:程序博客网 时间:2024/05/03 04:42

问题描述:

甲说:乙在说谎;乙说:丙在说谎;丙说:甲乙两个人都在说谎。法官为难,甲乙丙三个人到底谁在说谎?

分析:

甲(真)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

#include <stdio.h>int main(void){int a,b,c;for(a = 0;a <2;a++){for(b = 0;b <2;b++){for(c = 0;c < 2;c++){if(( a&&!b || !a&&b )&&( b&&!c || !b&&c )&&( c&&a+b == 0 || !c&&a+b != 0 )){printf("甲 told a %s.\n",a?"truth":"lie");         printf("乙 told a %s.\n",b?"truth":"lie");printf("丙 told a %s.\n",c?"truth":"lie");}}}}return 0;}



 

 

 

0 0