UVa 489, Purple book P79, hangman games

Source: Internet
Author: User

Title Link: https://uva.onlinejudge.org/external/4/489.pdf

This question is like a topological sort of topic before, the idea is similar.

Program modularity:

Each time a letter is judged, Lose,win is determined to exit directly.

Tips:

You can use the array guess[] to record whether each letter has been accessed. If it had been visited, counts++ was a mistake.

Here Ru Jia's little trick is, every time the same word assigned value for ", record the length of str1, check out str1 on win. Otherwise you are chickened out.

#include <stdio.h>#include<string.h>intwin, lose;intLeft ;intCounts =0;Charstr1[ the],str2[ the];voidGuessCharch) {    BOOLFlag =false;  for(intI=0; I<strlen (str1); i++)    {        if(ch==Str1[i]) {Str1[i]=' '; Flag=true; Left--; }    }    if(!flag) counts++; if(counts>6) Lose =1; if(left==0) win =1;}intMain () {Freopen ("Input.txt","R", stdin); intcases;  while(SCANF ("%d",&cases)) {Counts=0; if(cases==-1) Break; printf ("Round%d\n", cases); scanf ("%s%s", STR1,STR2); Win= lose =0; Left=strlen (STR1);  for(intI=0; I<strlen (str2); i++) {guess (str2[i]); if(win| |lose) Break; }        if(Win) printf ("You win.\n"); Else if(lose) printf ("You lose.\n"); Elseprintf"You chickened out.\n"); }    return 0;}

UVa 489, Purple book P79, hangman games

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.