2016-08-03 Problem Solving►UVa UVa 489 - Hangman Judge Contents 1. Problem2. Solution3. Code Problem中文網址 Solution直接看出現哪些字母,去模擬猜的過程即可。 CodeUVa 489123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960#include<cstdio>int main(){ int round; while (scanf("%d", &round) && round != -1) { getchar(); bool used[26] = {}, ans[26] = {}; int count = 0, hangman = 7; char c; while ((c = getchar()) != '\n') { if (!used[c - 'a']) { used[c - 'a'] = true; count++; } if (count == 26) { while ((c = getchar()) != '\n'); break; } } while ((c = getchar()) != '\n') { int temp = c - 'a'; if (!ans[temp]) { ans[temp] = true; if (used[temp]) { used[temp] = false; count--; } else hangman--; } if (!hangman || !count) { while ((c = getchar()) != '\n'); break; } } printf("Round %d\n", round); if (!hangman) puts("You lose."); else if (count) puts("You chickened out."); else puts("You win."); } return 0;} Newer UVa 615 - Is It A Tree Older Machine Learning Foundations - L4 Notes(下)