UVa 489 Hangman Judge

又是一个星期五, 开始发UVa的代码了啊!

比较忙的我没有太多练习题目的时间,所以就简简单单的找了一道水题来做,这道题没什么可以说的,所以就直接附上代码

地址在vjudge.net或UVa上

//yifei Wa
//UVa 489 Hangman Judge
#include <stdio.h> 
#include <string.h> //strlen() 
#define maxn 300 

int t, chance;
char com[maxn];

void guess(char a) {
    int fl = 0; 
    for(int i = 0; i < strlen(com); i++) {
        if(a == com[i]) { com[i] = ' '; fl = 1; t--; }    
    } 
    if(!fl) chance--;
}

int main() 
{
    int r;
    while(scanf("%d", &r) != EOF && r != -1) {
        scanf("%s", com);
        t = strlen(com);
        char a;  
        chance = 7; 
        getchar(); 
        for(;;) {
            a = getchar(); 
            if(a == '\n' || !chance || !t) break;
            guess(a); 
            //printf("%d %d\n", chance, t); 
        } 
        //while
        while(a != '\n') a = getchar(); 
        printf("Round %d\n", r); 
        if(!t) printf("You win.\n"); 
        else if(!chance) printf("You lose.\n"); 
        else printf("You chickened out.\n"); 
    }
    return 0;
} 

 

posted @ 2018-12-21 22:22  yifei_Wa  阅读(142)  评论(0编辑  收藏  举报