A + B

   

题目描述:
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
输入:
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
输出:
对每个测试用例输出1行,即A+B的值.
样例输入:
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
样例输出:
3
90
96
来源:
2005年浙江大学计算机及软件工程研究生机试真题

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

    int f(char s[])
    {
            if(s[0] == 'z')                        return 0;
            else if(s[0] == 'o')                   return 1;
            else if(s[0] == 't' && s[1] == 'w')    return 2;
            else if(s[0] == 't' && s[1] == 'h')    return 3;
            else if(s[0] == 'f' && s[1] == 'o')    return 4;
            else if(s[0] == 'f' && s[1] == 'i')    return 5;
            else if(s[0] == 's' && s[1] == 'i')    return 6;
            else if(s[0] == 's' && s[1] == 'e')    return 7;
            else if(s[0] == 'e')                   return 8;
            else if(s[0] == 'n')                  return 9;
            else return -1;
    }

    int main(void)
    {
            char s[5];

            while(scanf("%s",s) != EOF)
            {
                    int a,b;
                    a = f(s);
                    while(scanf("%s",s) != EOF)
                    {
                            if(s[0] != '+' && s[0] != '=')
                            {
                                    a *= 10;
                                    a += f(s);
                            }
                            else if(s[0] == '+')
                            {
                                    b = a;
                                    a = 0;
                            }
                            else if(s[0] == '=')
                                    break;
                    }
                    if(a || b)
                            printf("%d ",a+b);
                    else
                            return 0;
            }
            return 0;
    }

原文地址:https://www.cnblogs.com/wft1990/p/4297897.html