zoj 1926

13 篇文章 0 订阅
/*
zoj_1926    模拟
木有想到一道水题纠结那么久,见错误代码。。
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <limits.h>
using namespace std;

int main()
{
    //freopen("a.txt","r",stdin);
    int n,i,low,high;
    string say;
    bool cheat;
    while( cin>>n && n )
    {
        cin.get();
        cheat=false;
        low=0;  high=11;
        while( getline(cin,say) && say!="right on" )
        {
            if( say=="too high" &&   high>n )
                high=n;
            else if( say=="too low" && low<n )
                low=n;
            cin>>n;
            cin.get();
        }
        if( n<=low || n>=high )
             cheat=true;
        if( cheat ) cout<<"Stan is dishonest\n";
        else cout<<"Stan may be honest\n";
    }
    return 0;
}


/*一个错误代码。。
  其实归根到底是我想错了,我以为只要n不在那个范围那么stan就骗人了。。
  其实不是。那个n是猜测者猜的而已,要判断stan有没有骗人是要看stan对猜测者猜n时说的话的。。
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <limits.h>
using namespace std;

int main()
{
    //freopen("a.txt","r",stdin);
    int n,i,low,high;
    string say;
    bool cheat;
    while( cin>>n && n )
    {
        cin.get();
        cheat=false;
        low=-INT_MAX;  high=INT_MAX;
        while( getline(cin,say) && say!="right on" )
        {
            if( say=="too high" )
            {
                if( n<=low ) || n>=high )  //这里明显错了,可是我一直没看出来。。。
                    cheat=true;     //如果n>=high并且stan说too high那么stan是没有骗他的。。
                else if( high>n )
                    high=n;
            }
            else if( say=="too low" )
            {
                if( n<=low || n>=high )  //这边同理,也是错的
                    cheat=true;
                else if( low<n )
                    low=n;
            }
            cin>>n;
            cin.get();
        }
        if( n<=low || n>=high )
             cheat=true;
        if( cheat ) cout<<"Stan is dishonest\n";
        else cout<<"Stan may be honest\n";
    }
    return 0;
}
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值