UVA 489-Hangman Judge

猜单词游戏每次猜1个字母猜错的次数不能大于7 另外猜一个已经猜过的字母也算错
<pre name="code" class="cpp">#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#define Maxn 105
char s1[Maxn],s2[Maxn];
typedef long long ll;
using namespace std;
int win,lose;
int remaining,chance;
void guess(char c)
{   int bad=1;
    for(int i=0;i<strlen(s1);i++)

        if(s1[i]==c)

           {
              remaining--;
            s1[i]=' ';
            bad=0;
           }

        if(bad) --chance;
        if(!chance) lose=1;
        if(!remaining) win=1;


}
int main()
{   int n;
    while(~scanf("%d%s%s",&n,s1,s2)&&n!=-1)
    {
        printf("Round %d\n",n);
        win=lose=0;
        remaining=strlen(s1);
        chance=7;
        for(int i=0;i<strlen(s2);i++)
        {
            guess(s2[i]);
            if(win||lose) break;
        }
        if(win) printf("You win.\n");
        else if(lose) printf("You lose.\n");
        else printf("You chickened out.\n");
    }
    return 0;
}

 
 

你可能感兴趣的:(UVA 489-Hangman Judge)