489 - Hangman Judge
Hangman Judge
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:
______
| |
| O
| /|\
| |
| / \
__|_
| |______
|_________|
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.
,
copy from
#include <stdio.h>
#include <string.h>
#define MAX 104
char answer[MAX];
char guess[MAX];
int alpha[MAX];
int main()
{
int a, i, j;
while (scanf("%d", &a) && a != -1)
{
getchar();
int flag, stroke = 0;
memset(alpha, 1, MAX);
gets(answer);
gets(guess);
printf("Round %d
", a);
for (i = 0; i < strlen(guess); i++)
{
flag = 0;
if (alpha[guess[i] - 'a'])
{
for (j = 0; j < strlen(answer); j++)
if (guess[i] == answer[j])
{
answer[j] = '0';
flag = 1;
}
alpha[guess[i] - 'a'] = 0;
if (!flag)
stroke++;
}
if (stroke == 7)
{
printf("You lose.
");
flag = 1;
break;
}
flag = 1;
for (j = 0; j < strlen(answer); j++)
{
if (answer[j] != '0')
{
flag = 0;
break;
}
}
if (flag)
{
printf("You win.
");
break;
}
}
if (!flag)
printf("You chickened out.
");
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
application ---- enter and save the file codeInput file name and content - input_content.html Receive content and save file and content - input_content01.jsp...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.