Last active
September 26, 2018 17:31
-
-
Save WindAzure/d0d2a11f0ad9fedac7d2f2ecb99b865d to your computer and use it in GitHub Desktop.
UVa 489
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #define MAX_ERROR_TIMES 7 | |
| bool solutionCharacterTable[26]; | |
| bool guessCharacterTable[26]; | |
| int main() | |
| { | |
| auto round = 0; | |
| while (~scanf("%d", &round) && round != -1) | |
| { | |
| getchar(); | |
| printf("Round %d\n", round); | |
| memset(solutionCharacterTable, false, sizeof(bool) * 26); | |
| memset(guessCharacterTable, false, sizeof(bool) * 26); | |
| auto inputCharacter = ' '; | |
| auto solutionCharactersLen = 0; | |
| while ((inputCharacter = getchar()) && inputCharacter != '\n') | |
| { | |
| auto character = inputCharacter - 'a'; | |
| if (!solutionCharacterTable[character]) | |
| { | |
| solutionCharacterTable[character] = true; | |
| solutionCharactersLen++; | |
| } | |
| } | |
| auto errorTimes = 0; | |
| auto correctTimes = 0; | |
| auto isOutputAnswer = false; | |
| while ((inputCharacter = getchar()) && inputCharacter != '\n') | |
| { | |
| if (isOutputAnswer) | |
| { | |
| continue; | |
| } | |
| auto character = inputCharacter - 'a'; | |
| if (!guessCharacterTable[character]) | |
| { | |
| guessCharacterTable[character] = true; | |
| if (!solutionCharacterTable[character]) | |
| { | |
| errorTimes++; | |
| if (errorTimes >= MAX_ERROR_TIMES) | |
| { | |
| puts("You lose."); | |
| isOutputAnswer = true; | |
| } | |
| } | |
| else | |
| { | |
| correctTimes++; | |
| if (correctTimes == solutionCharactersLen) | |
| { | |
| puts("You win."); | |
| isOutputAnswer = true; | |
| } | |
| } | |
| } | |
| } | |
| if(!isOutputAnswer) | |
| { | |
| puts("You chickened out."); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment