zoukankan      html  css  js  c++  java
  • HDOJ.1228 A + B (map)

    A + B

    点我挑战题目
    点我一起学习STL-MAP

    题意分析

    讲字符串和数字用map对应即可

    代码总览

    /*
        Title:HDOJ.1228
        Author:pengwill
        Date:2016-11-21
    */
    #include <iostream>
    #include <map>
    #include <string>
    using namespace std;
    typedef map<string,int> mmp;
    mmp p;
    mmp::iterator iter1,iter2,iter3;
    
    string s1,s2,s3,s4,s5,s6;
    int main()
    {
        cin.sync_with_stdio(false);
        cin.tie(0);
        p["zero"] = 0;
    p["one"] = 1;
    p["two"] = 2;
    p["three"] = 3;
    p["four"] = 4;
    p["five"] = 5;
    p["six"] = 6;
    p["seven"] = 7;
    p["eight"] = 8;
    p["nine"] = 9;
        while(cin>>s1>>s2>>s3){
            if(s2.compare("+") == 0){
                if(s1.compare("zero")==0 && s3.compare("zero")==0){
                    break;
                }else{
                    cin>>s4;
                    if(s4.compare("=") == 0){
                        iter1 = p.find(s1);iter2 = p.find(s3);
                        cout<<iter1->second + iter2->second<<endl;
                    }else{
                        int a;
                        cin>>s5;
                        iter3 = p.find(s1);
                        iter1 = p.find(s3);iter2 = p.find(s4);
                        a = iter1->second * 10 + iter2->second;
                        cout<<a+ iter3->second <<endl;
                    }
    
                }
            }else{
                int a,b;
                iter1 = p.find(s1);iter2 = p.find(s2);
                a = iter1->second * 10 + iter2->second;
                cin>>s1>>s2;
                if(s2.compare("=") == 0){
                   // cout<<s2<<endl;
                    iter3 = p.find(s1);
                    b = iter3->second;
                   // cout<<s1<<endl;
                   // cout<<iter3->second<<endl;
                    cout<<a + b<<endl;;
                }else{
                    cin>>s3;
                    iter1 = p.find(s1);iter2 = p.find(s2);
                    b = iter1->second * 10 + iter2->second;
                    cout<<a+b<<endl;
                }
    
            }
        }
    
        return 0;
    }
    
  • 相关阅读:
    思考-少写代码
    app上传 那些事儿!
    vs2010 找不到本地服务器
    如何成为一名优秀得程序员
    python成功之路,Day2-判断和循环语句
    python成功之路,Day1-发展历史
    ES6学习笔记2-字符串扩展
    ES6学习笔记1-解构赋值
    数组的方法
    ES6
  • 原文地址:https://www.cnblogs.com/pengwill/p/7367220.html
Copyright © 2011-2022 走看看