• HDOJ 1228 A+B(map水题)


    A + B

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 8539    Accepted Submission(s): 4810


    Problem 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
    View Code
     1 #include <iostream>
     2 #include <string>
     3 #include <map>
     4 #include <utility>
     5 using namespace std;
     6 
     7 map <string, int> f;
     8 
     9 int main() {
    10     int sum1, sum;
    11     string str;
    12     f["one"]=1;
    13     f["zero"]= 0;
    14     f["two"]= 2;
    15     f["three"] = 3;
    16     f["four"]=4;
    17     f["five"]=5;
    18     f["six"]=6;
    19     f["seven"]=7;
    20     f["eight"]=8;
    21     f["nine"]=9;
    22     while(1)
    23     {
    24         sum=0;
    25         while(1)
    26         {
    27             cin>>str;
    28             if(str=="+")
    29             break;
    30             sum=sum*10+f[str];
    31         }
    32         sum1=0;
    33         while(1)
    34         {
    35             cin>>str;
    36             if(str=="=")
    37             break;
    38             sum1=sum1*10+f[str];
    39         }
    40         
    41         if(sum==0 && sum1 ==0)
    42         break;
    43         cout <<sum+sum1<< endl;
    44     }
    45     return  0;
    46 }
  • 相关阅读:
    下载视频
    009 逻辑 + MFC CString
    008 浅拷贝与深拷贝
    007 operator
    006 this指针原理
    005 逻辑 + STL list
    004 list::sort
    003 逻辑 + mfc CList
    001 C++历史和思想
    并查集模板
  • 原文地址:https://www.cnblogs.com/wanglin2011/p/2612010.html
Copyright © 2020-2023  润新知