B - 小学生的游戏
某天,无聊的小斌叫上几个同学玩游戏,其中有比较笨的小兴,比较傻的小雪,可爱的小霞和自以为是的小楠。他们去找聪明的小明去给他们当裁判。判定谁取得游戏胜利。
而这个游戏是由小斌想个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>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
using namespace std;
bool eq(char *a,char *b);
char a[15],b[]="too low",rt[]="right on";
int num;
struct game{
bool status;
int num;
game(char *a, int n) {
status = eq(a,b);
num = n;
}
};
stack<game> s;
bool check() {
while (!s.empty()) {
if ( (s.top().num<num) != s.top().status || s.top().num==num)
return false;
s.pop();
}
return true;
}
bool eq(char *a, char *b) {
while (*a && *a==*b){a++;b++;}
return *a==*b;
}
int main()
{
while (~scanf("%d",&num) && num) {
scanf("%c",a);
cin.getline(a,15);
if (eq(a,rt)) {
printf(check()?"The guy may be honest\n":"The guy is dishonest\n");
while (!s.empty())s.pop();
}
else {
s.push(game(a,num));
}
}
return 0;
}