1026: a+b问题

题目描述

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

输入

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

输出

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

样例输入

one + two =
three four + five six =
zero + zero =

样例输出

3
90

来源/分类

 
#include<string>
#include<string.h>
#include<iostream>
#include<map>

using namespace std;
map<string, int>arr = {
    {"zero",0},
    {"one",1},
    {"two",2},
    {"three",3},
    {"four",4},
    {"five",5},
    {"six",6},
    {"seven",7},
    {"eight",8},
    {"nine",9},
};


int getAorB() {
    string str_a;
    int result = 0;
    while (cin >> str_a) {
        if (str_a == "+" || str_a == "=")break;
        result = result * 10 + arr[str_a];
    }
    return result;
}

int main() {
    string str;
    while (true){
        int A = 0, B = 0;
        A = getAorB();
        B = getAorB();
        if (A == 0 && B == 0)return 0;
        cout << A + B << endl;
    }
    return 0;
}

 

posted @ 2020-08-18 01:03  我是happy唐啊  阅读(165)  评论(0编辑  收藏  举报