uva 489

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 follows:

  1. The contestant tries to solve to puzzle by guessing one letter at a time.
  2. Every time a guess is correct, all the characters in the word that match the guess will be ``turned over.‘‘ For example, if your guess is ``o‘‘ and the word is ``book‘‘, then both ``o‘‘s in the solution will be counted as ``solved.‘‘
  3. Every time a wrong guess is made, a stroke will be added to the drawing of a hangman, which needs 7 strokes to complete. Each unique wrong guess only counts against the contestant once.
       ______
       |  |
       |  O
       | /|\
       |  |
       | / \
     __|_
     |   |______
     |_________|
  4. If the drawing of the hangman is completed before the contestant has successfully guessed all the characters of the word, the contestant loses.
  5. If the contestant has guessed all the characters of the word before the drawing is complete, the contestant wins the game.
  6. If the contestant does not guess enough letters to either win or lose, the contestant chickens out.

Your task as the ``Hangman Judge‘‘ is to determine, for each game, whether the contestant wins, loses, or fails to finish a game.

Input

Your program will be given a series of inputs regarding the status of a game. All input will be in lower case. The first line of each section will contain a number to indicate which round of the game is being played; the next line will be the solution to the puzzle; the last line is a sequence of the guesses made by the contestant. A round number of -1 would indicate the end of all games (and input).

Output

The output of your program is to indicate which round of the game the contestant is currently playing as well as the result of the game. There are three possible results:

You win.
You lose.
You chickened out.

Sample Input

1
cheese
chese
2
cheese
abcdefg
3
cheese
abcdefgij
-1

Sample Output

Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.

水题还wa.真是药丸.药丸啊...

 1 /*************************************************************************
 2     > File Name: code/uva/489.cpp
 3     > Author: 111qqz
 4     > Email: [email protected]
 5     > Created Time: 2015年09月23日 星期三 19时34分34秒
 6  ************************************************************************/
 7
 8 #include<iostream>
 9 #include<iomanip>
10 #include<cstdio>
11 #include<algorithm>
12 #include<cmath>
13 #include<cstring>
14 #include<string>
15 #include<map>
16 #include<set>
17 #include<queue>
18 #include<vector>
19 #include<stack>
20 #include<cctype>
21 #define y1 hust111qqz
22 #define yn hez111qqz
23 #define j1 cute111qqz
24 #define ms(a,x) memset(a,x,sizeof(a))
25 #define lr dying111qqz
26 using namespace std;
27 #define For(i, n) for (int i=0;i<int(n);++i)
28 typedef long long LL;
29 typedef double DB;
30 const int inf = 0x3f3f3f3f;
31 const int N=30;
32 int a[N];
33 int main()
34 {
35   #ifndef  ONLINE_JUDGE
36    freopen("in.txt","r",stdin);
37   #endif
38     int cas;
39     while (scanf("%d",&cas)!=EOF)
40     {
41     if (cas==-1) break;
42     ms(a,0);
43     printf("Round %d\n",cas);
44
45     string st1,st2;
46     cin>>st1>>st2;
47     int len1 = st1.length();
48     for ( int i = 0 ; i < len1 ; i++)
49     {
50         int tmp = st1[i]-‘a‘;
51         a[tmp]++;
52     }
53     int len2 = st2.length();
54     int cnt = 0 ;
55     int sum = 0 ;
56     int state = 0;
57     for ( int i = 0 ; i < len2 ; i++)
58     {
59         int tmp = st2[i]-‘a‘;
60         if (a[tmp]==0)
61         {
62         cnt++;
63         }
64         else
65         {
66         sum += a[tmp];
67         a[tmp] =  0;
68         }
69         if (cnt>=7) break;
70         if (sum==len1)
71         {
72         state = 1;
73         break;
74         }
75     }
76     if (state ==1)
77     {
78         puts("You win.");
79         continue;
80     }
81 //    cout<<"cnt:"<<cnt<<endl;
82     if (cnt<7)
83     {
84         puts("You chickened out.");
85     }
86     else
87     {
88         puts("You lose.");
89     }
90     }
91
92  #ifndef ONLINE_JUDGE
93   fclose(stdin);
94   #endif
95     return 0;
96 }

时间: 2024-08-11 05:44:51

uva 489的相关文章

UVa 489 HangmanJudge --- 水题

UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜过的单词也算出错, 给定计算机的单词以及猜测序列,判断玩家赢了(You win).输了(You lose).放弃了(You chickened out) /* UVa 489 HangmanJudge --- 水题 */ #include <cstdio> #include <cstring

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,紫书P79,刽子手游戏

题目链接:https://uva.onlinejudge.org/external/4/489.pdf 这个题很像之前的一个拓扑排序的题目,思路类似咯. 程序模块化: 每次判断一个字母,lose,win确定就直接退出. 小技巧: 你可以用数组guess[]记录每个字母是否访问过.要是已经访问过,counts++,算是一种错误. 这里汝佳的小技巧是,每次把相同的字符赋值为‘ ’,记录一下str1的长度,查完str1就win.否则就是You chickened out. #include <stdi

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 con

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

寒假练习 01

这一系列的练习主要在Virtual Judge上进行,题目为小白书上的题目推荐. UVa 10055 注意两个数的大小关系,水题. #include <iostream> using namespace std; int main() { long long x, y; while(cin >> x >> y) { if(x > y) { swap(x, y); } cout << y - x << endl; } return 0; }

UVa 568 Just the Facts

A过去后看了一下别人的解法,发现除了打表还有一种数论的方法. 分析一下阶乘后面的0是怎么出现的呢,当然是2乘5得到的. 我们将1~N先放在一个数组里面. 从数组第一个元素开始,先统计一下N!中因子为5的个数记为count,将其除去,然后再除去count个2.这样一来的话把所有元素乘起来后就不会出现10的倍数了. 当然并不是真正的乘起来,那样的话肯定是要溢出的,因为只关心最后一位数,所以每次乘完后求10的余数即可. 我的做法是打表,因为题目里给了N <= 10000的条件限制,所以可以把1~100

【暑假】[深入动态规划]UVa 1412 Fund Management

UVa 1412 Fund Management 题目: UVA - 1412 Fund Management Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Frank is a portfolio manager of a closed-end fund for Advanced Commercial Markets (ACM ). Fund