Guessing Game
Problem F: Guessing Game
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 20 Solved: 6
[ Submit][ Status][ Web Board]
Description
Stan and Ollie are playing a guessing game. Stan thinks of a number between 1 and 10 and Ollie guesses what the number might be. After each guess, Stan indicates whether Ollie’s guess is too high, too low, or right on.
After playing several rounds, Ollie has become suspicious that Stan cheats; that is, that he changes the number between Ollie’s guesses. To prepare his case against Stan, Ollie has recorded a transcript of several games. You are to determine whether or not each transcript proves that Stan is cheating.
Standard input consists of several transcripts. Each transcript consists of a number of paired guesses and responses. A guess is a line containing single integer between 1 and 10, and a response is a line containing “too high”, “too low”, or “right on”. Each game ends with “right on”. A line containing 0 follows the last transcript.
For each game, output a line “Stan is dishonest” if Stan’s responses are inconsistent with the final guess and response. Otherwise, print “Stan may be honest”.
Input
Output
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
Stan is dishonest
Stan may be honest
HINT
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
int n,mx,mn,flag;
char s[30];
flag=0;
mx=11;mn=-1;
while(scanf("%d",&n)&&n)
{
getchar();
gets(s);
if(strcmp(s,"right on")==0)
{
if(flag==0&&n<mx&&n>mn)
{
cout<<"Stan may be honest"<<endl;
}
else
{
cout<<"Stan is dishonest"<<endl;
}
mx=11;
mn=-1;
flag=0;
}
if(strcmp(s,"too high")==0)
{
if(n<=mn)
{
flag=1;
}
else if(n<mx)
{
mx=n;
}
}
if(strcmp(s,"too low")==0)
{
if(n>=mx)
{
flag=1;
}
else if(n>mn)
{
mn=n;
}
}
}
}
还没有评论,来说两句吧...