UVA 489 Hangman Judge (character matching)

Source: Internet
Author: User

Test instructions: Give a string A with a number of lowercase characters. Give a string B, with a number of lowercase characters. The rules are as follows:

1. String b is traversed from left to right, and for each character, if the character exists in a, all of the characters in A are deleted and, if not present, the number of errors is +1.

2, when the number of errors reached 7, the game ended, lost lose.

3, when the string A has no characters, the game is over, won win. (The string B does not have to traverse the back)

4, when the number of errors did not reach 7, but the string A and the remaining characters are not eliminated, then chickened out.

The wrong 7 to lose, before the full 7 match is finished before winning, in the full 7 before the chickened out of a match.

Train of thought: the string a statistics 26 characters whether appear (with hash), traverse string B, each match successfully deleted 26 letters corresponding to that, matching failure on the statistics whether to reach 7 times.

1#include <bits/stdc++.h>2 #defineLL Long Long3 using namespacestd;4 Const intn=129;5 intHas1[n], num[n];6 strings1, S2;7 8 intCal ()//match is-1, greater than 0 less than 7 is dangling, greater than 7 is hanging up9 {Ten     intcnt1=0, cnt3=0; One      for(intI=0; I<s1.size (); i++) has1[s1[i]]++; A      for(intI='a'; i<='Z'; i++)if(has1[i]>0) cnt1++;//How many matches do we need? -  -      for(intI=0; I<s2.size (); i++) the     { -         if(Has1[s2[i]])//matching the -         { -has1[s2[i]]=0; +cnt1--;//and a match. -             if(!CNT1)return-1;//the match is done +         } A         Elsecnt3++;//of the wrong at         if(cnt3>=7)return Ten;//7 of the wrong one. -     } -     returnCnt3; - } -  -  in intMain () - { toFreopen ("E://input.txt","R", stdin); +     intN; -      while(SCANF ("%d", &n),n>0) the     { *printf"Round%d\n", n); $memset (HAS1,0,sizeof(HAS1));Panax Notoginsengmemset (NUM,0,sizeof(num)); -Cin>>s1>>S2; the         inttmp=cal (); +         if(tmp==-1) printf ("You win.\n"); A         Else if(tmp<7) printf ("You chickened out.\n"); the         Elseprintf"You lose.\n"); +     } -     return 0; $}
AC Code

UVA 489 Hangman Judge (character matching)

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.