UVa 489-hangman Judge

Source: Internet
Author: User

Https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_ problem&problem=430

Title: Guess the word game, the rules are as follows:

1. The guessing person guesses one letter at a time;

2. Every time the quiz is correct, all the characters in the word are guessed correctly;

3. Guess the wrong guesses 7 times, then the guessing person loses; the same character counts only one error;

4. The guessing person guesses all the characters, then the guessing person wins. If you have not won or lose the quiz, then the guessing person give up;

  sample Input   
1
cheese
chese
Span style= "FONT-SIZE:13PX;" >2
cheese
ABCDEFG
3
cheese
abcdefgij
-1

sample Output
round 1
you win.
round 2
you chickened out.
round 3
you lose.

Idea: Because all the inputs are lowercase letters, use an array of AA to record the characters that appear in the guessing word. And then traverse the guessing of the sequence, if aa[s[i]-' a ']=1, then guessed, otherwise there is no guess, the number of records did not guess count, if count>=7 the guessing loser;

If Count<7 and aa[i]!=0 exist, the guessing person will give up the game. If the count<7 and AA array values are 0, the guessing winner wins.

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 intMain ()7 {8   //freopen ("Input.txt", "R", stdin);9    intt,count,i,j;Ten    strings1,s2; One    intaa[ -]; A    BOOLflag,f; -     while(cin>>t&&t!=-1) -    { thef=false; -flag=false; -Count=0; -memset (AA,0,sizeof(AA)); +Cin>>s1>>S2; -       for(i=0; I<s1.length (); i++) +aa[s1[i]-'a']=1; A       for(j=0; J<s2.length (); j + +) at          { -           if(aa[s2[j]-'a']) -aa[s2[j]-'a']=0; -           Else -count++; -          if(count>=7) in                 Break; -           for(i=0;i< -; i++) to             if(Aa[i]) +              { -flag=true; the                  Break; *              } $          if(flag)Panax Notoginseng            { -flag=false; the                Continue; +            } Af=true; the              Break; +          } -cout<<"Round"<<t<<Endl; $         if(count>=7) $cout<<"You lose."<<Endl; -         Else if(f) -cout<<"You win."<<Endl; the            Else  -cout<<"You are chickened out."<<Endl; Wuyi      } the         return 0;

UVa 489-hangman Judge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.