Skip to content

Instantly share code, notes, and snippets.

@WindAzure
Last active September 26, 2018 17:31
Show Gist options
  • Select an option

  • Save WindAzure/d0d2a11f0ad9fedac7d2f2ecb99b865d to your computer and use it in GitHub Desktop.

Select an option

Save WindAzure/d0d2a11f0ad9fedac7d2f2ecb99b865d to your computer and use it in GitHub Desktop.
UVa 489
#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