zoukankan      html  css  js  c++  java
  • 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;
        }

  • 相关阅读:
    JS统计还可以输入多少字数,用于向输入者提示信息
    php系统 骑士cms(74cms)个人版 整合UC
    win7下使用wamp server 使用PHP5.3配置Zend guard loader 注意事项,失败
    linux crontab定时任务运行shell脚本(shell执行sql文件)
    POJ 1179 Polygon
    POJ 1189 钉子和小球
    HDU 3788 ZOJ问题
    POJ 1191 棋盘分割【区间类DP】
    POJ 1338 Ugly Numbers
    假期学习第一步之......学习堆排序
  • 原文地址:https://www.cnblogs.com/wft1990/p/4297897.html
Copyright © 2011-2022 走看看