暴力破解a+b

A + B

http://www.nowcoder.com/questionTerminal/5fb3548802bb4a13a10c2e53a6fbfdd9

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

char num[10][6]={"zero","one","two","three","four","five","six","seven","eight","nine"};

int main()
{
    int a,b,i;
    char s[6];
    while(scanf("%s",&s)!=EOF)
    {
        for(i=0;i<10;i++)
        {
            if(!strcmp(num[i], s))
            {
                a=i;
                break;
            }
        }
        scanf("%s",&s);
        if(strcmp(s,"+")!=0)
        {
            a*=10;
            for(i=0;i<10;i++)
            {
                if(!strcmp(num[i], s))
                {
                    a+=i;
                    break;
                }
            }
            scanf("%s",&s);
            scanf("%s",&s);
            for(i=0;i<10;i++)
            {
                if(!strcmp(num[i], s))
                {
                    b=i;
                    break;
                }
            }
            scanf("%s",&s);
            if(!strcmp(s,"="))
            {
                printf("%d\n",a+b);
            }
            else{
                b*=10;
                for(i=0;i<10;i++)
                {
                    if(!strcmp(num[i], s))
                    {
                        b+=i;
                        break;
                    }
                }
                scanf("%s",&s);
                printf("%d\n",a+b);
            }
        }
        else{
            scanf("%s",&s);
            for(i=0;i<10;i++)
            {
                if(!strcmp(num[i], s))
                {
                    b=i;
                    break;
                }
            }
            scanf("%s",&s);
            if(a==0&b==0)
                break;
            else
                printf("%d\n",a+b);
        }
    }
    return 0;
}


多次输入,然后条件判断(•̀ᴗ•́)و
全部评论

相关推荐

面试摇了我吧:啊哈哈面试提前五个小时发,点击不能参加就是放弃
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
10-05 10:13
已编辑
HHHHaos:让这些老登来现在秋招一下,简历都过不去
点赞 评论 收藏
分享
评论
2
1
分享
牛客网
牛客企业服务