Hangman Judge
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Practice
UVA 489
Description
Download as PDF
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
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Practice
UVA 489
Description
Download as PDF
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.
题目大意:玩一个翻牌游戏,将写有字符的牌盖在桌子上,让游戏者猜逐个猜字符,猜对哪个字符,就将写有该字符的牌面反过来,如果你已经猜错了7次,那么你输了,输出You lose. 如果牌面全反过来了,那么你赢了,输出You win.,如果牌面还没有全部翻过来,而且你还没有猜错7次,那么你胆怯了,输出You chickened out.(注意:猜相同的字符既不算对,也不算错)。
/*AC*/
#include<stdio.h>
#include<string.h>
int main()
{
int t;
while (scanf("%d",&t))
{
if (t==-1)
break;
char a[100],b[100];
int c[100]={0},lena,lenb,k=0;
scanf("%s%s",a,b);
lena=strlen(a);
lenb=strlen(b);
for (int i=0;i<lena;i++)
{
if (c[a[i]-'a']!=1)
{
c[a[i]-'a']=1; //把所有不重复的字母标记为1
k++;
}
}
int rig=0,wro=0; //统计回答正确和回答错误的次数
for (int i=0;i<lenb;i++)
{
if (c[b[i]-'a']==1)
{
rig++;
c[b[i]-'a']=2; //标记这个字母为2,防止读入重复字母
}
if (c[b[i]-'a']==0) //这里不能用else,因为重复字母不能算答错
wro++;
if (rig==k) //如果全部猜对必须跳出循环,否者后面猜错的会使wro>=7
break;
}
printf("Round %d\n",t);
if (wro>=7)
printf("You lose.\n");
else if (rig!=k)
printf("You chickened out.\n");
else
printf("You win.\n");
}
return 0;
}