码迷,mamicode.com
首页 > 其他好文 > 详细

uva 489.Hangman Judge 解题报告

时间:2015-09-29 18:38:27      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

题目链接: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\n", 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.\n");
45         else if (lose) printf("You lose.\n");
46         else printf("You chickened out.\n");
47     }
48     return 0;
49 }

 

uva 489.Hangman Judge 解题报告

标签:

原文地址:http://www.cnblogs.com/windysai/p/4846654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!