FZU 1575 小学生的游戏

 

小学生的游戏
Time Limit:1s Memory limit:32M
Accepted Submit:307 Total Submit:1057

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

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

数据输入

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

数据输出

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

样例输入

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

样例输出

The guy is dishonest
The guy may be honest

Original: FOJ月赛-2008年3月

 

解题:

       一度被陷进迷雾里,关于数据方面要多考虑些,特别是边界。

       例如:

               1

                too low
               1 
               right on

 

#include <iostream> using namespace std; int main() { int n,a,b,flag; a=1;flag=1; b=10000000; char c[8]; while(cin>>n && n!=0) { cin>>c>>c; if(c[0]=='h') { if(n<b) b=n; if(n==10000000) flag=0; } else if(c[0]=='l') { if(n>a) a=n; if(n==1) flag=0; } else { if(n>a && n<b || (a==1 && b==10000000 && flag) || (n>a && b==10000000 && flag) || (n<b && a==1 && flag)) cout<<"The guy may be honest"<<endl; else cout<<"The guy is dishonest"<<endl; a=1;b=10000000;flag=1; } } return 0; }

你可能感兴趣的:(游戏,c,任务)