POJ 2328 Guessing Game(我的水题之路——猜数字测谎)
2012-02-10 20:52
507 查看
Guessing Game
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.
Input
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.
Output
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
Sample Output
Source
Waterloo local 2003.07.05
猜数字游戏比较熟悉,是说先确定一个正确数字,另一个人猜数字,然后回答猜测数字比正确数字是太高、太低还是正确。现在题中给定猜测的过程,让我们用程序验证这个猜测过程中,回答是否正确。
一拿到这道题,先想的是否能够边读入边判断,因为这样会很简单,但是发现不行,因为正确的数字只有在最后才能得到,所以用两个int数组getnum、answer分别记录猜测的数字和猜测结果,其中answer数组用-1/1/0分别表是“too low”、“too high”、“right on”.直到读取到正确的数字,将它保存,然后从头验证getnum中第i个元素的比较结果和answer中第i条记录是否相符,如果全部相符则说明全部正确,输出“Stan may be honest”,发现有不符合的立刻退出循环,输出“Stan
is dishonest”.
代码(1AC):
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12345 | Accepted: 4333 |
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.
Input
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.
Output
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
Source
Waterloo local 2003.07.05
猜数字游戏比较熟悉,是说先确定一个正确数字,另一个人猜数字,然后回答猜测数字比正确数字是太高、太低还是正确。现在题中给定猜测的过程,让我们用程序验证这个猜测过程中,回答是否正确。
一拿到这道题,先想的是否能够边读入边判断,因为这样会很简单,但是发现不行,因为正确的数字只有在最后才能得到,所以用两个int数组getnum、answer分别记录猜测的数字和猜测结果,其中answer数组用-1/1/0分别表是“too low”、“too high”、“right on”.直到读取到正确的数字,将它保存,然后从头验证getnum中第i个元素的比较结果和answer中第i条记录是否相符,如果全部相符则说明全部正确,输出“Stan may be honest”,发现有不符合的立刻退出循环,输出“Stan
is dishonest”.
代码(1AC):
#include <cstdio> #include <cstdio> #include <cstring> char str[3][20]={"too high", "too low", "right on"}; int answer[1100]; // -1 too low, 1 too high, 0 right on int getnum[1100]; int getanswer(char ans[]){ if (strcmp(str[0], ans) == 0){ return 1; } else if (strcmp(str[1], ans) == 0){ return -1; } else if (strcmp(str[2], ans) == 0){ return 0; } } int main(void){ char tmp[20]; int num, rightnum; int i, j; int flag; // 0 dishonst 1 honst while (scanf("%d", &num), num != 0){ getchar(); gets(tmp); answer[0] = getanswer(tmp); getnum[0] = num; for (i = 0; answer[i] != 0; ){ i++; scanf("%d", &num); getchar(); gets(tmp); answer[i] = getanswer(tmp); getnum[i] = num; } rightnum = getnum[i]; i++; // i means the number of the responses for (flag = 1, j = 0; j < i - 1; j++){ if (getnum[j] - rightnum > 0 && answer[j] == 1 ){ continue; } else if (getnum[j] - rightnum < 0 && answer[j] == -1){ continue; } else{ flag = 0; break; } } if (flag){ printf("Stan may be honest\n"); } else if (flag == 0){ printf("Stan is dishonest\n"); } } return 0; }
相关文章推荐
- POJ 2328 Guessing Game(一道让我想哭的水题!)
- POJ 2328 Guessing Game
- poj 2328 Guessing Game
- POJ 2328 Guessing Game
- POJ 2328 Guessing Game(水~)
- POJ 2328 Guessing Game
- poj 2328 Guessing Game
- Poj 2328 Guessing Game(猜数字游戏)
- Poj 2328 Guessing Game(猜数字游戏)
- zoj 1926 || poj 2328 Guessing Game(水~)
- poj 3589 Number-guessing Game(水题)
- POJ 2328 Guessing Game G++
- poj 2328 Guessing Game
- poj2328 Guessing Game
- poj 1753 Flip Game(搜索:DFS+水题)
- POJ 1528 Perfection(我的水题之路——因子之和)
- POJ 2039 To and Fro(我的水题之路——解密,N个字符的正逆序)
- POJ 2909 Goldbach's Conjecture(我的水题之路——任一数为素数对之和)
- POJ3589 Number-guessing Game
- POJ 1543 Perfect Cubes(我的水题之路——四重暴力水)