码迷,mamicode.com
首页 > 其他好文 > 详细

UVA_489:Hangman Judge

时间:2015-04-03 22:29:56      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

技术分享技术分享

技术分享

Language:C++ 4.8.2

 


#include<stdio.h>
#include<string.h>
int main(void)
{
    char str_original[30];
    char str_guessed[30];
    int arr_ori[30];
    int mark[30]; // 标记数组
    int n, fail_sum, success_sum, total_word;
    int ok; // 猜测成功与否的标志
    while(1)
    {
        scanf("%d\n", &n);
        if(n == -1)
            break;
        memset(arr_ori, 0, sizeof(arr_ori));
        memset(mark, 0, sizeof(mark));
        fail_sum = success_sum = total_word = 0;
        scanf("%s", str_original); 
        scanf("%s", str_guessed);
        
        int len_ori = strlen(str_original);
        for(int i = 0; i < len_ori; i++)
        {
            arr_ori[str_original[i] - a] = 1;
        }
        
        
        for(int i = 0; i < 30; i++)
        {
            if(arr_ori[i])
                total_word++;
        }
        int len_gue = strlen(str_guessed);
        
        int i;
        for(i = 0; i < len_gue; i++)
        {
            success_sum = 0;
            ok = 0;
            for(int j = 0; j < len_ori; j++)
            {
                if(str_guessed[i] == str_original[j])
                {
                    ok = 1;
                    mark[str_guessed[i] - a] = 1;
                    break;
                }
            }
            for(int k = 0; k < 30; k++)
                if(mark[k]) success_sum++;
                    
            if(success_sum == total_word)
            {
                printf("Round %d\nYou win.\n", n); // 去掉\n,WA
                break;
            }
                
            fail_sum += !ok;
            if(fail_sum == 7)
            {
                printf("Round %d\nYou lose.\n", n);        
                break;                
            }
        }
        if(i == len_gue)
            printf("Round %d\nYou chickened out.\n", n);
    }
    return 0;
}

UVA_489:Hangman Judge

标签:

原文地址:http://www.cnblogs.com/xpjiang/p/4391036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!