Han gm an Judge 模拟
来源:互联网 发布:sgd算法 矩阵分解 编辑:程序博客网 时间:2024/04/18 03:48
A CM Conte st Problems Archive Univers ity of Valladolid (SPAIN)
489 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 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 b e \turned
over." For example, if your guess is \o" and the word is \b o ok", then b oth \o"s in the solution
will b e counted as \solved."
3. Every time a wrong guess is made, a stroke will b e added to the drawing of a hangman, which
needs 7 strokes to complete. Each unique wrong guess only counts against the contestant once.
4. If the drawing of the hangman is completed b efore 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 b efore the drawing is complete, the
contestant wins the game.
6. If the contestant do es 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 nish a game.
Input
Your program will b e given a series of inputs regarding the status of a game. All input will b e in lower
case. The rst line of each section will contain a numb er to indicate which round of the game is b eing
played; the next line will b e the solution to the puzzle; the last line is a sequence of the guesses made
by the contestant. A round numb er 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 p ossible 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.
题目大意:一个类似于猜单词的游戏,如果你猜对一个答案中包含的字母,那么所有字母都会显示,如果猜的是答案中不包含的字母或者已经猜过的字母,对方得一分。如果对方先得到7分,你就输了;如果你先猜出所有的字母,你就赢了;最后不赢不输就是放弃了。
思路:首先统计答案中每一个字母是否出现,然后再计算出答案中所有不相同的字母总数,接着遍历猜测的顺序,如果字母不存在或者已经猜过,对方加一分,否则自己加一分。如果对方先达到7分,就输了,如果自己先猜出所有字母,就赢了,否则就放弃。
#include <iostream>#include <stdio.h>#include <string.h>#define MAX 100000using namespace std;int main(){ int round,res_c[26],len,i; int sov,sto,uni; int win; char res[MAX],guess[MAX]; while(~scanf("%d",&round)&&round!=-1) { scanf("%s%s",res,guess); memset(res_c,0,sizeof(res_c)); win=uni=sov=sto=0; len=strlen(res); for(i=0; i<len; i++) res_c[res[i]-'a']++; for(i=0;i<26;i++) if(res_c[i]!=0) uni++; len=strlen(guess); for(i=0; i<len; i++) { if(res_c[guess[i]-'a']==0||res_c[guess[i]-'a']==-1) { sto++; res_c[guess[i]-'a']=-1; } else { res_c[guess[i]-'a']=-1; sov++; } if(sto==7) { printf("Round %d\n",round); printf("You lose.\n"); win=1; break; } else if(sov==uni) { printf("Round %d\n",round); printf("You win.\n"); win=1; break; } } if(win==0) { printf("Round %d\n",round); printf("You chickened out.\n"); } } return 0;}
- Han gm an Judge 模拟
- Land oj 1609 - Han Move (模拟)
- uva489 Hangman Judge (模拟)
- UVa 489 Hangman Judge [模拟]
- HDU6023-Automatic Judge-简单模拟
- UVa 489 Hangman Judge (模拟&字符串匹配)
- PAT 1075. PAT Judge (模拟题)
- 【基础练习】【模拟】Uva489 - Hangman Judge题解
- PTA PAT Judge 【模拟题,未完待续】
- C. Multi-judge Solving 贪心+模拟
- HDU 6023 Automatic Judge (模拟)
- How to judge if an iterator is used before.
- 【Peking University Online Judge】2453(An Easy Problem)
- How to judge whether an array is empty?
- judge
- Judge
- ZOJ 1005 Jugs(模拟 special judge,也可以BFS)
- HDOJ1073(Online Judge)(模拟+容器的使用)
- [48]Rotate Image
- mysql 导出 sql 执行sql
- iOS的常见问题---Object-C有私有方法吗?私有变量呢?多重继承?
- 【Leetcode】之ZigZag Conversion
- cnetos 6----install ---- rpmfusion
- Han gm an Judge 模拟
- 操作系统-概念
- C++ string 用法概览
- java读取属性文件properties文件
- Unity之NGUIUIButton点击事件的带参传递
- JavaEE JavaSE
- Gradient Boosting Decision Tree学习
- bug反馈
- Filter(过滤器)学习