Skip to main content
  1. Posts/

uva 489

·2 mins
Table of Contents
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

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: rkz2013@126.com
 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
26using namespace std;
27#define For(i, n) for (int i=0;i<int(n);++i)
28typedef long long LL;
29typedef double DB;
30const int inf = 0x3f3f3f3f;
31const int N=30;
32int a[N];
33int 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}

Related

poj 2739 Sum of Consecutive Prime Numbers (尺取法)

·1 min
一开始迷之wa… 先找出素数下标的上界就可以A… 然后纠结了20分钟... 然后发现是预处理的素数少了一个素数.. 我预处理是处理到<10005的素数... 最大数10000,而超过10000的第一个素数是10007 这样判断终止条件就会死循环… sad

poj 2100 Graveyard Design (two pointers ,尺取法)

·1 min
不多说,直接代码。 1/************************************************************************* 2 > File Name: code/poj/2100.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年09月25日 星期五 00时42分49秒 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 26using namespace std; 27#define For(i, n) for (int i=0;i<int(n);++i) 28typedef long long LL; 29typedef double DB; 30const int inf = 0x3f3f3f3f; 31LL n; 32LL maxn; 33vector<LL>ans; 34 35 36void solve() 37{ 38 LL head = 1,tail = 1; 39 LL sum = 0 ; 40 41 while (tail<=maxn) 42 { 43 sum = sum + tail*tail; 44 45 if (sum>=n) 46 { 47 while (sum>n)//主要是while,因为可能要减掉多个才能小于n 48 { 49 sum -= head*head; 50 head++; 51 } 52 if (sum==n) 53 {//因为要先输出答案个数...所以必须存起来延迟输出... 54 ans.push_back(head); 55 ans.push_back(tail); 56 } 57 } 58 tail++; 59 } 60 LL sz = ans.size(); 61 printf("%lld\n",sz/2); 62 for (LL i = 0 ; i<ans.size() ; i = i +2) 63 { 64 printf("%lld",ans[i+1]-ans[i]+1); 65 for ( LL j = ans[i] ; j <=ans[i+1] ; j++) printf(" %lld",j); 66 printf("\n"); 67 } 68 69} 70int main() 71{ 72 #ifndef ONLINE_JUDGE 73 freopen("in.txt","r",stdin); 74 #endif 75 scanf("%lld",&n); 76 maxn = ceil(sqrt(n)); 77 solve(); 78 79 #ifndef ONLINE_JUDGE 80 fclose(stdin); 81 #endif 82 return 0; 83}