In Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follows:
- The contestant tries to solve to puzzle by guessing one letter at a time.
- Every time a guess is correct, all the characters in the word that match the guess will be
turned over.'' For example, if your guess is
o'' and the word is
book'', then both
o''s in the solution will be counted as
solved.''
- Every time a wrong guess is made, a stroke will be added to the drawing of a hangman, which needs 7 strokes to complete. Each unique wrong guess only counts against the contestant once.
- ______
- | |
- | O
- | /|\
- | |
- | / \
- __|_
- | |______
|_________|
- If the drawing of the hangman is completed before the contestant has successfully guessed all the characters of the word, the contestant loses.
- If the contestant has guessed all the characters of the word before the drawing is complete, the contestant wins the game.
- If the contestant does not guess enough letters to either win or lose, the contestant chickens out.
Your task as the Hangman Judge'' is to determine, for each game, whether the contestant wins, loses, or fails to finish a game.
Input
Your program will be given a series of inputs regarding the status of a game. All input will be in lower case. The first line of each section will contain a number to indicate which round of the game is being played; the next line will be the solution to the puzzle; the last line is a sequence of the guesses made by the contestant. A round number of -1 would indicate the end of all games (and input).
Output
The output of your program is to indicate which round of the game the contestant is currently playing as well as the result of the game. There are three possible results:
You win.
You lose.
You chickened out.
Sample Input
1
cheese
chese
2
cheese
abcdefg
3
cheese
abcdefgij
-1
Sample Output
Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.
题目类型:简单字符处理
算法分析:本题对于存贮玩家猜的字符串每一个字符,调用一次guess函数来判断在完成对于该字符处理之后是否进行退出。注意将玩家猜过的字符改成空格,下面第二个代码是更好的实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
/************************************************** filename :b.cpp author :maksyuki created time :2017/12/3 22:30:29 last modified :2017/12/5 8:02:29 file location :C:\Users\abcd\Desktop\TheEternalPoet ***************************************************/ #pragma comment(linker, "/STACK:102400000,102400000") #include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; #define CFF freopen ("in", "r", stdin) #define CFO freopen ("out", "w", stdout) #define CPPFF ifstream cin ("in") #define CPPFO ofstream cout ("out") #define DB(ccc) cout << #ccc << " = " << ccc << endl #define DBT printf("time used: %.2lfs\n", (double) clock() / CLOCKS_PER_SEC) #define PB push_back #define MP(A, B) make_pair(A, B) typedef long long LL; typedef unsigned long long ULL; typedef double DB; typedef pair <int, int> PII; typedef pair <int, bool> PIB; const int INF = 0x7F7F7F7F; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 1e5 + 6666; char sa[maxn], sb[maxn]; void solve(char c) { for(int i = 0; sa[i]; i++) if(sa[i] == c) sa[i] = '*'; } int main() { #ifdef LOCAL CFF; //CFO; #endif int id; while(scanf(" %d", &id) != EOF) { if(id == -1) break; scanf(" %s %s", sa, sb); int cnt = 0; bool is_find; for(int i = 0; sb[i]; i++) { if(cnt > 6) break; is_find = false; for(int j = 0; sa[j]; j++) { if(sb[i] == sa[j]) { solve(sb[i]); is_find = true; } } if(!is_find) cnt++; } printf("Round %d\n", id); bool is_win = true; for(int i = 0; sa[i]; i++) if(sa[i] != '*') { is_win = false; break; } if(is_win) puts("You win."); else { if(cnt > 6) puts("You lose."); else puts("You chickened out."); } } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
#include <cstdio> #include <iostream> #include <fstream> #include <cstring> using namespace std; const int maxn = 106; char com[maxn], ply[maxn]; bool win, lose; int chance, comleave; void guess (char ch) { int bad = 1, len = strlen (com), i; for (i = 0; i < len; i++) { if (com[i] == ch) { comleave--; com[i] = ' '; bad = 0; } } if (bad) chance--; if (!chance) lose = true; if (!comleave) win = true; } int main() { int id; //ifstream cin ("aaa.txt"); while (cin >> id >> com >> ply && id != -1) { win = lose = false; chance = 7; comleave = strlen (com); int i, len = strlen (ply); for (i = 0; i < len; i++) { guess (ply[i]); if (win || lose) break; } printf ("Round %d\n", id); if (win) printf ("You win.\n"); else if (lose) printf ("You lose.\n"); else printf ("You chickened out.\n"); } return 0; } |
- « 上一篇:uva11809
- uva133:下一篇 »