100c之50:到底谁在说谎

Table of Contents

问题

谁在说谎:张三说李四说谎,李四说王五在说谎,王五说张三和李四都在说谎。现在问这三个人中谁在说谎?

分析

每个人有两种状态:说谎;诚实。张三和李四的状态对立,李四和王五的状态对立,王五和张三李四都撒谎的状态对立。

程序

 1:  /**
 2:   * @file   050c.c
 3:   * @author Chaolong Zhang <emacsun@163.com>
 4:   * @date   Wed Jul 10 10:58:28 2013
 5:   * 
 6:   * @brief  谁在说谎:张三说李四说谎,李四说王五在说谎,王五说张三和李四都在说谎。现在问这三个人中谁在说谎?
 7:   * 
 8:   * 
 9:   */
10:  
11:  #include <stdio.h>
12:  
13:  #define N 2
14:  int main(int argc, char *argv[])
15:  {
16:      int san,si,wu;
17:      int san1,si1,si2,wu1;
18:          for ( san = 0; san < N; ++san){
19:              for ( si = 0; si < N; ++si){
20:                  for ( wu = 0; wu < N; ++wu){
21:                      if ( ( san&&!si || !san&&si ) && 
22:                           ( si&&!wu || !si&&wu) && 
23:                           ( wu&&( san+si == 0 ) || !wu&&( san+si !=0 ) )){
24:                          printf ("zhang san=%s;li si=%s;wang wu=%s",san?"ture":"lie",si?"true":"lie",wu?"true":"lie");
25:                      }
26:                  }
27:              }
28:          }
29:      return 0;
30:  }

结果

zhang san=lie;li si=true;wang wu=lie
posted @ 2013-07-09 21:26  emacsun  阅读(300)  评论(0编辑  收藏  举报