Uva 489 Hangman Judge

题意我理解了很久,英语不好的伤不起,把英文看懂就知道写了,纯模拟题,不难,题意明白就好,纯C写的

 

#include<stdio.h>
#include<string.h>

#define MAX 100

char s[MAX];
char s1[MAX];

int pang(char c);
int f1();
void fun();

int pang(char c)
{
    int i,flag=0;
    int len;
    len=strlen(s);
    for(i=0;i<len;i++)
    {
        if(c==s[i])
        {
            s[i]='0';
            flag=1;
        }
    }
    return flag;
}

int f1()
{
    int i;
    int len;
    int flag=0;
    len=strlen(s);
    for(i=0;i<len;i++)
    {
        if(s[i]!='0')
            return 0;
    }
    return 1;
}

void fun()
{
    int i,j;
    int len,len1;
    int hang=0;
    len=strlen(s);
    len1=strlen(s1);
    for(i=0;i<len1;i++)
    {
        if(!pang(s1[i]))
        {
            hang++;
        }
        if(hang>=7)
        {
            printf("You lose.\n");
                return;
        }
        else if(hang<7)
        {
            if(f1()==1)
            {    
                printf("You win.\n");
                return;
            }
            
        }
    }
    if(hang<7)
        printf("You chickened out.\n");
} 


int main()
{
    int n;
    while(scanf("%d",&n)!=EOF&&n!=-1)
    {
        memset(s,'\0',sizeof(s));
        memset(s1,'\0',sizeof(s1));
        scanf("%s",s);
        scanf("%s",s1);
        printf("Round %d\n",n);
        fun();
    }
    return 0;
}


 

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