Hust oj 2121 你猜猜(水题)

来源:互联网 发布:朝鲜奢侈生活知乎 编辑:程序博客网 时间:2024/04/30 19:49
你猜猜Time Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 270(70 users)Total Accepted: 91(62 users)Rating: Special Judge: NoDescription


ACM集训队不培训的闲暇时间里,Woods就会和他的GrilFriendGF)玩一些小游戏(咳咳…不要邪恶)。GF为了考验Woods和她的默契程度,玩了个“你猜猜”的游戏,规则如下:

GF在心里想一个数,然后Woods开始猜,对于Woods每次猜的数,GF可以有三种回答:too hightoo lowright on。分别表示太高了,太低了,猜对了。Woods非常了解GF,每次都很快猜对。但是GF非常好强,有的时候就是不想让Woods猜对,于是她可能会故意错误的回答。请你判断一下,GF到底有没有故意回答错误?(参见第一组样例。Woods10GF说太高了。Woods3GF说太低了。Woods4GF说太高了。Woods2GF说对了。但显然2不是正确答案。因为Woods3的时候就已经太低了。)


Input

多组测试数据。每组数据包含许多组猜测。每组猜测包括两行,第一行为一个数字代表Woods猜的数,第二行为GF的一个回答,只包含too hightoo lowright on三种。每组数据以right on结束。

Output
    每组数据输出一行。如果GF没有故意回答错误,输出"GF may be honest."如果GF有故意错误回答,输出"GF is dishonest."(引号不输出)。
Sample Input10
too high
3
too low
4
too high
2
right on
5
too low
7
too high
6
right on
Sample Output

GF is dishonest.GF may be honest.

读第一遍的时候没反应过来,还以为是什么难题,后来才明白,用两个数组分别存low和high,再用right和他们分别比较,如果比low小或者比high大都是错的,要注意等于也算错的,因为这个WA了一发

#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;const int maxn = 105;int high[maxn];int low[maxn];char a[maxn];int main(){    int n;    int cnt1 = 0,cnt2 = 0;    int flag = 0;    while(~scanf("%d",&n))    {        getchar();        gets(a);        if(strcmp(a,"too high") == 0)        {            high[cnt1++] = n;        }        if(strcmp(a,"too low") == 0)        {            low[cnt2++] = n;        }        if(strcmp(a,"right on") == 0)        {            for(int i=0;i<cnt1;i++)            {                if(n >= high[i])                {                    flag = 1;                    break;                }            }            for(int i=0;i<cnt2;i++)            {                if(n <= low[i] || flag == 1)                {                    flag = 1;                    break;                }            }            if(flag == 1)                printf("GF is dishonest.\n");            else                printf("GF may be honest.\n");            cnt1 = 0;            cnt2 = 0;            flag = 0;        }    }    return 0;}


 

0 0
原创粉丝点击