Guessing Game
2013-03-31 15:52
295 查看
Guessing Game
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".
解析:题意是猜数字游戏。开始Stan 想一个1到10的数a。然后Ollie 去猜,如果大于a则Stan 说too
high,小于则说too low。如果相等则说right on。但是Stan会说谎,所以通过stan的回答来判断是否Stan说谎。
思路:用一个1到10的数组,来标记还在范围内的数。例如说一个数n,如果给的是too high,则大于等于n的数都可以标记不合法了。
当出现right on时,看数组中是否还有数。如果还有就可以判断Stan可能没说谎。
#include"stdio.h"
#include"string.h"
int main()
{
int n,x,y,i,j,k;
char s[20];
int a[11];
while(scanf("%d",&n)!=EOF&&n)
{
memset(a,0,sizeof(a));
while(gets(s)&&strcmp(s,"right on"))
{
if(!strcmp(s,"too high"))
{
for(i=n;i<=10;i++)
a[i]=1;
}
if(!strcmp(s,"too low"))
{
for(i=n;i>=1;i--)
a[i]=1;
}
scanf("%d",&n);
}
if(a
==0)
printf("Stan may be honest\n");
else
printf("Stan is dishonest\n");
}
return 0;
}
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".
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
解析:题意是猜数字游戏。开始Stan 想一个1到10的数a。然后Ollie 去猜,如果大于a则Stan 说too
high,小于则说too low。如果相等则说right on。但是Stan会说谎,所以通过stan的回答来判断是否Stan说谎。
思路:用一个1到10的数组,来标记还在范围内的数。例如说一个数n,如果给的是too high,则大于等于n的数都可以标记不合法了。
当出现right on时,看数组中是否还有数。如果还有就可以判断Stan可能没说谎。
#include"stdio.h"
#include"string.h"
int main()
{
int n,x,y,i,j,k;
char s[20];
int a[11];
while(scanf("%d",&n)!=EOF&&n)
{
memset(a,0,sizeof(a));
while(gets(s)&&strcmp(s,"right on"))
{
if(!strcmp(s,"too high"))
{
for(i=n;i<=10;i++)
a[i]=1;
}
if(!strcmp(s,"too low"))
{
for(i=n;i>=1;i--)
a[i]=1;
}
scanf("%d",&n);
}
if(a
==0)
printf("Stan may be honest\n");
else
printf("Stan is dishonest\n");
}
return 0;
}
相关文章推荐
- (Relax ST1.16)POJ 3589 Number-guessing Game(求连个字符串中相同的字符有多少个和同位置&&同字符的字符个数有多少个)
- poj 2328 Guessing Game
- poj 3589 Number-guessing Game
- poj2328 Guessing Game
- 【贪心】【poj 4028】GCD Guessing Game
- UVA 题目1521 GCD Guessing Game(数论+贪心)
- poj 2328 Guessing Game
- POJ 2328 Guessing Game(一道让我想哭的水题!)
- Guessing Game
- Guessing Game解题报告 (pku 2328)
- UVA 1521 - GCD Guessing Game(数论+贪心)
- POJ 2328 Guessing Game
- POJ 3589 Number-guessing Game(水~)
- BZOJ2632: [neerc2011]Gcd guessing game
- Poj 2328 Guessing Game(猜数字游戏)
- UVALive - 7715 Guessing Game
- ZOJ 1926 Guessing Game
- POJ 2328 Guessing Game(水~)
- ZOJ Problem Set - 1926 Guessing Game
- poj 2328 Guessing Game