题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=430
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 using namespace std; 6 7 const int maxn = 100; 8 9 int l, chance; 10 char s[maxn], s2[maxn]; 11 int win, lose; 12 13 void guess(char ch) 14 { 15 int bad = 1; 16 for (int i = 0; i < strlen(s); i++) { 17 if (s[i] == ch) { 18 l--; 19 s[i] = '#'; 20 bad = 0; 21 } 22 } 23 if (bad) --chance; 24 if (!chance) lose = 1; 25 if (!l) win = 1; 26 } 27 28 int main() 29 { 30 int rnd; 31 #ifndef ONLINE_JUDGE 32 freopen("in.txt", "r", stdin); 33 #endif // ONLINE_JUDGE 34 while (scanf("%d%s%s", &rnd, s, s2) == 3 && rnd != -1) { 35 printf("Round %d ", rnd); 36 win = lose = 0; 37 l = strlen(s); 38 chance = 7; 39 for (int i = 0; i < strlen(s2); i++) { 40 guess(s2[i]); 41 if (win || lose) break; 42 } 43 44 if (win) printf("You win. "); 45 else if (lose) printf("You lose. "); 46 else printf("You chickened out. "); 47 } 48 return 0; 49 }