• hdu 1228 A + B


    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=1228

    A + B

    Description

    读入两个小于100的正整数A和B,计算A+B.
    需要注意的是:A和B的每一位数字由对应的英文单词给出.

    Input

    测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出. 

    Output

    对每个测试用例输出1行,即A+B的值.

    Sample Input

    one + two =
    three four + five six =
    zero seven + eight nine =
    zero + zero =

    Sample Output

    3

    90

    96

    字符串水题。。

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<string>
     7 #include<vector>
     8 #include<map>
     9 #include<set>
    10 using std::map;
    11 using std::cin;
    12 using std::cout;
    13 using std::endl;
    14 using std::vector;
    15 using std::string;
    16 #define sz(c) (int)(c).size()
    17 #define all(c) (c).begin(), (c).end()
    18 #define iter(c) decltype((c).begin())
    19 #define cls(arr,val) memset(arr,val,sizeof(arr))
    20 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    21 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    22 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
    23 #define pb(e) push_back(e)
    24 #define mp(a, b) make_pair(a, b)
    25 const int Max_N = 100010;
    26 typedef unsigned long long ull;
    27 map<string, int> rec;
    28 void init() {
    29     rec["zero"] = 0;
    30     rec["one"] = 1;
    31     rec["two"] = 2;
    32     rec["three"] = 3;
    33     rec["four"] = 4;
    34     rec["five"] = 5;
    35     rec["six"] = 6;
    36     rec["seven"] = 7;
    37     rec["eight"] = 8;
    38     rec["nine"] = 9;
    39 }
    40 int main() {
    41 #ifdef LOCAL
    42     freopen("in.txt", "r", stdin);
    43     freopen("out.txt", "w+", stdout);
    44 #endif
    45     init();
    46     int a, b, f;
    47     char str[100], buf[100];
    48     while (gets(buf)) {
    49         a = b = f = 0;
    50         char *p = buf;
    51         while (true) {
    52             if (*p == ' ') { p++; continue; }
    53             sscanf(p, "%s", str);
    54             if (!strcmp(str, "=")) break;
    55             if (!f && strcmp(str, "+")) a = a * 10 + rec[str];
    56             if (!strcmp(str, "+") || f) {
    57                 if (!strcmp(str, "+")) { f = 1, p++; continue; }
    58                 b = b * 10 + rec[str];
    59             }
    60             p = p + strlen(str);
    61         }
    62         if (!(a + b)) break;
    63         printf("%d
    ", a + b);
    64     }
    65     return 0;
    66 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    Docker windows下安装,入门及注意事项,并搭建包含Nodejs的webapp
    360浏览器table中的td为空时td边框不显示的解决方法
    关于发布webservice提示The test form is only available for requests from the local machine
    CRM相关SQl手记
    页面右下角弹出的消息提示框
    MS CRM2011 js常用总结
    MVC razor 使用服务器控件
    常用正则表达式
    CRM 2011 常用对象
    人工智能AI-机器视觉CV-数据挖掘DM-机器学习ML-神经网络-[资料集合贴]
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4595747.html
Copyright © 2020-2023  润新知