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 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.
    1. ______
    2. | |
    3. | O
    4. | /|\
    5. | |
    6. | / \
    7. __|_
    8. | |______
    9. |_________|
  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:

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

Sample Input

  1. 1
  2. cheese
  3. chese
  4. 2
  5. cheese
  6. abcdefg
  7. 3
  8. cheese
  9. abcdefgij
  10. -1

Sample Output

  1. Round 1
  2. You win.
  3. Round 2
  4. You chickened out.
  5. Round 3
  6. You lose.

一个字符串的游戏  有一个你不知道的字符串  你開始有7条命  然后你每次猜一个字母  若你猜的字母在原字符串中  原字符串就去掉全部那个字母  否则你失去一条命   假设你在命耗完之前原字符串中全部的字母都被猜出  则你赢   假设你在命耗完了原字符串中还有字母没被猜出  则你输    假设你在命没耗完原字符串中也还有字母没被猜出  视为你放弃

给你还有一个字符串作为你猜的顺序  推断你能否赢:

  1. //UVa489 Hangman
  2. #include<cstdio>
  3. #include<cstring>
  4. using namespace std;
  5. const int N = 1000;
  6. char a[N], b[N];
  7. int cas, la, lb, i, j;
  8. int main()
  9. {
  10. while (scanf ("%d", &cas), cas + 1)
  11. {
  12. scanf ("%s %s", a, b);
  13. la = strlen (a);
  14. lb = strlen (b);
  15. int ca[26] = {0}, left = 7;
  16. for (i = 0; i < la; ++i)
  17. ++ca[a[i] - 'a'];
  18. for (i = 0; i < lb; ++i)
  19. if (ca[b[i] - 'a'] != 0)
  20. {
  21. ca[b[i] - 'a'] = 0;
  22. for (j = 0; j < 26; ++j)
  23. if (ca[j] != 0) break;
  24. if (j == 26)
  25. {
  26. printf ("Round %d\nYou win.\n", cas);
  27. break;
  28. }
  29. }
  30. else if (--left == 0)
  31. {
  32. printf ("Round %d\nYou lose.\n", cas);
  33. break;
  34. }
  35. if (i == lb) printf ("Round %d\nYou chickened out.\n", cas);
  36. }
  37. return 0;
  38. }

UVa 489 Hangman Judge(字符串)的更多相关文章

  1. uva 489 Hangman Judge(水题)

    题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  2. uva 489.Hangman Judge 解题报告

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

  3. UVA 489 Hangman Judge (字符匹配)

    题意:给一个字符串A,只含小写字符数个.再给一个字符串B,含小写字符数个.规则如下: 1.字符串B从左至右逐个字符遍历,对于每个字符,如果该字符在A中存在,将A中所有该字符删掉,若不存在,则错误次数+ ...

  4. uva 489 Hangman Judge

    大意:电脑想个单词,玩家来猜.玩家输入一个个字母,若答案里有这个字母,则显示该单词中所有该字母.最终目标是显示答案所有字母.猜错7次,死: 注意特殊条件:1.玩家不断重复错误的字母,只算一次猜错.2. ...

  5. uvaoj 489 - Hangman Judge(逻辑+写代码能力)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. Hangman Judge UVA - 489

    In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each gam ...

  7. UVa 489 HangmanJudge --- 水题

    UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...

  8. UVA.12169 Disgruntled Judge ( 拓展欧几里得 )

    UVA.12169 Disgruntled Judge ( 拓展欧几里得 ) 题意分析 给出T个数字,x1,x3--x2T-1.并且我们知道这x1,x2,x3,x4--x2T之间满足xi = (a * ...

  9. UVA 12169 Disgruntled Judge 扩展欧几里得

    /** 题目:UVA 12169 Disgruntled Judge 链接:https://vjudge.net/problem/UVA-12169 题意:原题 思路: a,b范围都在10000以内. ...

随机推荐

  1. TensorFlow OOM when allocating tensor with shape[5000,384707]

    在session范围内不要进行eval()或者convert_to_tensor()操作, 否则会造成OOM,或者报出错误:GraphDef cannot be larger than 2GB usi ...

  2. 关于Python多线程condition变量的应用

    ''' 所谓条件变量,即这种机制是在满足了特定的条件后,线程才可以访问相关的数据. 它使用Condition类来完成,由于它也可以像锁机制那样用,所以它也有acquire方法和release方法,而且 ...

  3. Android ListView绑定数据

    ListView绑定数据的三层: ListView绑定数据源从逻辑上可以分为三层:UI层,逻辑层,数据层. UI层:UI层即是ListView控件. 数据层:要展示到ListView控件上面的数据. ...

  4. js文件中引用其他js文件

    这一个功能的作用是做自己的js包时,可以通过引入一个整体的js文件而引入其他js. 只需要在总体的js加上这一句话 document.write("<script type='text ...

  5. QT 杂记

    1.按F4切换designer和Edit视图. 2.加载同目录下的js文件: import "XXX.js" as MyJs //首字母一定要大写 3.qml 引用的js中对象.字 ...

  6. 如何让一个div里面的div垂直居中?

    如何让一个div里面的div垂直居中? 如何让上面灰色有文字那个div和背景图标垂直居中,不管屏幕大小有好大,始终在垂直方向上的中间.上面有整个布局和样式表,谢谢高手指点 CSS3时代当然要用CSS3 ...

  7. php第二十七节课

    注册审核 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  8. P1060 开心的金明(洛谷,动态规划递推,01背包轻微变形题)

    题目链接:P1060 开心的金明 基本思路: 基本上和01背包原题一样,不同点在于这里要的是最大重要度*价格总和,我们之前原题是 f[j]=max(f[j],f[j-v[i]]+p[i]); 那么这里 ...

  9. 洛谷——P2090 数字对

    P2090 数字对 题目描述 对于一个数字对(a, b),我们可以通过一次操作将其变为新数字对(a+b, b)或(a, a+b). 给定一正整数n,问最少需要多少次操作可将数字对(1, 1)变为一个数 ...

  10. 后台工具screen

    之前在putty之类的远程命令行操作服务器的时候,遇到关闭软件,对应的操作就会关闭.很多时候,就是开着电脑,然后挂在那里,虽然不用电脑跑,但是也耗电...主要是putty这些软件有时候会伴随黑屏崩掉. ...