标题:小小的人工智能问题 求解
只看楼主
weiqiang
Rank: 2
等 级:论坛游民
帖 子:48
专家分:52
注 册:2010-10-18
结帖率:70%
已结贴  问题点数:20 回复次数:6 
小小的人工智能问题 求解
题目:在一次会议上,A说B在说假话,B说C在说假话,C说A和B在说假话。试问谁在说假话,谁在说真话。

我程序如下不知道哪出错了它好像只执行一次循环
/*判断谁在说真话谁在说假话*/
#include <stdio.h>

int main()
{
    int A;
    int B;
    int C;
    int count = 0;
   
    for (A=0; A<2; A++)
    {
        for (B=0; B<2; B++)
        {
            for (C=0; C<2; C++)
            {
                count += ((A == 1 && B == 0) || (A == 0 && B ==1));
                count += ((B == 1 && C == 0) || (B == 0 && C == 1));
                count += ((C == 1 && A == 0 && B == 0) || (C == 0 && A == 1 && B== 1));
                goto finish;
            }
        }
    }
   
    finish : if (count == 3)
         {
             printf("A is saying %s.word\n", (A == 1) ? "true" : "false");
             printf("B is saying %s.word\n", (B == 1) ? "true" : "false");
             printf("C is saying %s.word\n", (C == 1) ? "true" : "false");
         }
    return 0;
}
搜索更多相关主题的帖子: 人工智能 
2011-01-13 10:01
huangapple
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:545
专家分:1790
注 册:2010-12-30
得分:3 
执行一次后就直接goto了。。。。你应该把if放上面去,再把goto放if里面去,然后试试。。。


[ 本帖最后由 huangapple 于 2011-1-13 10:45 编辑 ]

勤能补拙,熟能生巧!
2011-01-13 10:34
逐渐学习
Rank: 6Rank: 6
等 级:侠之大者
帖 子:113
专家分:454
注 册:2010-9-26
得分:3 
c是清白的。

#include <stdio.h>

int main()
{
    int A;
    int B;
    int C;
    int count = 0;
   
    for (A=0; A<2; A++)
    {
        for (B=0; B<2; B++)
        {
            for (C=0; C<2; C++)
            {
                count += ((A == 1 && B == 0) || (A == 0 && B ==1));
                count += ((B == 1 && C == 0) || (B == 0 && C == 1));
                count += ((C == 1 && A == 0 && B == 0) || (C == 0 && A == 1 && B== 1));
                if (count == 2)
                    goto finish;
               
            }
        }
    }
   
   finish :

             printf("A is saying %s.word\n", (A == 1) ? "true" : "false");
             printf("B is saying %s.word\n", (B == 1) ? "true" : "false");
             printf("C is saying %s.word\n", (C == 1) ? "true" : "false");

    return 0;
}

帮人《---》帮己
2011-01-13 10:39
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:3 
#include <stdio.h>

int main()
{
    int A;
    int B;
    int C;
    int count = 0;
   
    for (A=0; A<2; A++)
    {
        for (B=0; B<2; B++)
        {
            for (C=0; C<2; C++)
            {
                count += ((A == 1 && B == 0) || (A == 0 && B ==1));
                count += ((B == 1 && C == 0) || (B == 0 && C == 1));
                count += ((C == 1 && A == 0 && B == 0) || (C == 0 && A == 1 && B== 1));
                if (count==3)  goto finish;//怎么的算法我不知道,但是根据你的意思,你看这样可以不?  
             }         
        }
    }
   
    finish:
             printf("A is saying %s word\n", (A == 1) ? "true" : "false");
             printf("B is saying %s word\n", (B == 1) ? "true" : "false");
             printf("C is saying %s word\n", (C == 1) ? "true" : "false");
             return 0;
}

   唯实惟新 至诚致志
2011-01-13 10:44
yangfanconan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:397
专家分:541
注 册:2009-9-22
得分:3 
逻辑运算,和逻辑   应该差好多。
2011-01-13 20:32
刘定邦
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:687
专家分:1570
注 册:2010-9-21
得分:3 
学习.
2011-01-13 22:39
hoovi
Rank: 2
等 级:论坛游民
帖 子:12
专家分:34
注 册:2010-11-3
得分:3 
口算了下B真话
2011-01-14 00:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-331022-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.553629 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved