Han gm an Judge 模拟

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 



cheese 
chese 

cheese 
abcdefg 

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 100000
using 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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值