uva 489.Hangman Judge 解题报告

题目链接: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 }
时间: 2024-08-09 19:53:48

uva 489.Hangman Judge 解题报告的相关文章

UVa 489 Hangman Judge(字符串)

 Hangman Judge  In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follo

UVa 489 Hangman Judge

题目大意: 这是一个猜单词的游戏. 输入回合数(但回合数为-1的时候停止) 再输入一个待猜的单词B 最后输入你猜的单词组合A. 这个猜单词比较有意思的地方是他一个一个判断. 从你输入的A中,按照顺序一个一个字母来判断. 当B中有这个字母的时候,这个字母就被标记(所有在B中相同的都被标记). 当B中没有这个字母的时候,就统计一次错. 若 所以字母都被标记了则获胜, 错误达到7次则失败. 若 判断完错误还不足7次, 也没标记完,则视为放弃. ★一定要注意是一个一个判断 Sample Input 1

UVA 489 Hangman Judge (字符匹配)

题意:给一个字符串A,只含小写字符数个.再给一个字符串B,含小写字符数个.规则如下: 1.字符串B从左至右逐个字符遍历,对于每个字符,如果该字符在A中存在,将A中所有该字符删掉,若不存在,则错误次数+1. 2.当错误次数达到7时,游戏结束,输了lose. 3.当串A中已经没有字符了,游戏结束,赢了win.(串B后面还没遍历到的也不用遍历了) 4.当错误次数没到达7,但是字符串A还有剩下的字符没消去,则chickened out. 错满7个就输,在满7个之前匹配完了就赢,在满7个之前没匹配完就ch

UVa -1584 Circular Sequence 解题报告

1.题目大意 输入长度为n$(2\le n\le 100)$的环状DNA串,找出该DNA串字典序最小的最小表示. 2.思路 这题特别简单,一一对比不同位置开始的字符串的字典序,更新result. 3.代码 #include"stdio.h" #include"string.h" #define maxn 100 int judge(char* s,int p,int q) //比较p的字典序是否比q小 { int m=strlen(s); for(int i=0;

UVA 10815 (STL_C题)解题报告

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756 -----------------------------------------------------------------------------------------------------------------------------------------

UVa 455 - Periodic Strings 解题报告

1.题目大意 求一个长度不超过80的字符串的最小周期. 2.思路 非常简单,基本就是根据周期的定义做出来的,几乎不需要过脑. 3.应该注意的地方 (1) 最后输出的方式要注意,不然很容易就PE了.不过个人认为,其实这题Sample Output给的不好 (2) 注意输出的要求是最小周期 4.代码 #include"stdio.h" #include"string.h" #define maxn 80 int main() { int T,m,i,j,flag; ch

UVA 11461 Square Numbers解题报告

Discription A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to find out how many square numbers are there between a and b (inclusive). In

uva 10881 Piotr&#39;s Ants 解题报告

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&page=show_problem&problem=1822 题目意思:有一条 L 厘米长的杆,上面有 n 只蚂蚁,给出每只蚂蚁的朝向以及离杆上最左端的距离,问 T 秒之后每只蚂蚁到达的位置,如果 T 秒后某个位置有多只蚂蚁同时到达,那么这堆蚂蚁处于的位置 + Turning,如果超过这条杆的长度,输出F

杭州电子科技大学Online Judge 之 “确定比赛名次(ID1285)”解题报告

杭州电子科技大学Online Judge 之 "确定比赛名次(ID1285)"解题报告 巧若拙(欢迎转载,但请注明出处:http://blog.csdn.net/qiaoruozhuo) Problem Description 有N个比赛队(1<=N<=500).编号依次为1,2,3,.....N进行比赛.比赛结束后.裁判委员会要将全部參赛队伍从前往后依次排名. 但如今裁判委员会不能直接获得每一个队的比赛成绩,仅仅知道每场比赛的结果.即P1赢P2,用P1.P2表示,排名时P