UVaOJ 489 - Hangman Judge

来源:互联网 发布:搜狐微博 知乎 编辑:程序博客网 时间:2024/05/06 03:34


#include <stdio.h>#include <string.h>#include <ctype.h>bool isWin(int a[]){    for(int i = 0; i<26; i++)    {        if(a[i] == 1) return false;    }    return true;}int main(){    freopen("in.txt","r",stdin);    int n;    while(scanf("%d",&n)&&n!=-1)    {        int flag[26]= {0};        memset(flag,0,sizeof(flag));        getchar();        char s[1000],d[1000];        gets(s);        int slen = strlen(s);        for(int i = 0 ; i<slen; i++)        {            flag[s[i]-'a'] = 1;        }        gets(d);        int dlen = strlen(d);        int error = 0;        bool win = false,isLose = false;        for(int i = 0; i<dlen; i++)        {            if(flag[d[i]-'a'] == 1)            {                flag[d[i]-'a']=2;            }            else if(flag[d[i]-'a'] == 2||flag[d[i]-'a'] == 3)            {                continue;            }            else            {                flag[d[i]-'a'] = 3;                error++;                if(error == 7)                {                    isLose = true;                    break;                }            }            if(isWin(flag))            {                win = true;                break;            }        }        printf("Round %d\n",n);        if(win)        {            printf("You win.\n");            continue;        }        if(isLose)        {            printf("You lose.\n");            continue;        }        printf("You chickened out.\n");    }    return 0;}

这个题花了比较长的 时间,囧~~

1、再提供三组测试数据,下面三种能过,基本就能A了。

                     4
                     cheeseab
                     cheeeeeeeeeeseabing
                     5
                     chinese
                     aaaaaaachinese
                     6
                     beautiful
                     beautiful 

2、

上面

第4组数据说的是:同一个字母猜对了多次

第5组数据说的是:同一个字母猜错了多次,只记 错一次

第6组数据说的是:一个很长的数据





0 0
原创粉丝点击