FZU 1575 小学生的游戏(水题)

    xiaoxiao2021-03-25  88

    某天,无聊的小斌叫上几个同学玩游戏,其中有比较笨的小兴,比较傻的小雪,可爱的小霞和自以为是的小楠。他们去找聪明的小明去给他们当裁判。判定谁取得游戏胜利。

    而这个游戏是由小斌想个1到10000000的数字让大家猜,看谁先猜中。为了防止小斌作弊,小明记录下了游戏的整个过程。你的任务是判断小斌是否有作弊。

    Input

    输入数据包括多盘游戏。一次猜数包含两行,第一行是一个数字n(1<=n<=10000000),表示所猜数字。第二行是小斌的回答为”too high”,”too low”,”right on”三种答案之一。每盘游戏结束于”right on”。当n=0的时候,整个游戏结束。

    Output

    对于每盘游戏,若小斌确有撒谎,请输出一行”The guy is dishonest”,否则请输出”The guy may be honest”。

    Sample Input 10 too high 3 too low 4 too high 2 right on 5 too low 7 too high 6 right on 0

    Sample Output The guy is dishonest The guy may be honest

    注意考虑边界情况就行了。

    #include<iostream> using namespace std; int main() { long long n,blag=1; char s1[10],s2[10]; long long l=1,r=10000001; while(cin>>n&&n) { cin>>s1>>s2; if(s1[0]=='r') { if(n>l&&n<r||(l==1&&r==10000000&&blag)||(n>l&&r==10000000&&blag)||(n<r&&l==1&&blag)) cout<<"The guy may be honest"<<endl; else cout<<"The guy is dishonest"<<endl; l=1,r=10000000,blag=1; } else if(s2[0]=='h') { if(n<r) r=n; if(n==10000000) blag=0; } else if(s2[0]=='l') { if(n>l) l=n; if(n==1) blag=0; } } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-25653.html

    最新回复(0)