欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVa489 Hangman Judge

程序员文章站 2024-03-19 08:20:10
...

题目传送门:https://vjudge.net/problem/UVA-489

题目很简单,不需要思路。

暴力解决,直接上代码:

#include<stdio.h>
#include<string.h>
int death;
char str0[1001];
char str1[1001];

int judge(char* str1, char * str2) {
     int left = strlen(str1);
    for(int i = 0; i < strlen(str2); i++) {
        int mark = 0;
        for(int j = 0; j < strlen(str1); j++) {
            if(str2[i] == str1[j]) {
                str1[j] = ' ';
                mark = 1;
                left--;
            }
        }
        if(!mark)
            death++;
        if(death == 7)
            return 3;
        if(!left)
            return 1;
    }
    return 2;
}

int main() {
    int n;
    memset(str0, '\0', sizeof(str0));
    memset(str1, '\0', sizeof(str1));   
    while(~scanf("%d", &n)) {
        if(n == -1) break;
        death = 0;
        scanf("%s%s", str0, str1);
        printf("Round %d\n", n);
        int result = judge(str0, str1);
        if(result == 1) printf("You win.");
        if(result == 2) printf("You chickened out.");
        if(result == 3) printf("You lose.");
        printf("\n");
        memset(str0, '\0', sizeof(str0));
        memset(str1, '\0', sizeof(str1));
    }
    return 0;
}
相关标签: uva