天天看點

ACM—STL使用<map>

#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
map <string ,int> num;
//map要加頭檔案還有我常忘記的using namespace std 
int main()
{
    num["one"]=1;
    num["two"]=2;
    num["three"]=3;
    num["four"]=4;
    num["five"]=5;
    num["six"]=6;
    num["seven"]=7;
    num["eight"]=8;
    num["nine"]=9;
    num["zero"]=0;
    string a;
    while(1)
    {
        int l=0;
        while(cin>>a,a!="+")//scanf("%s",&a),a!="+"不可以 
        {
            l=  l*10+num[a];
        }
        //cout<<l<<endl; 
        int r=0;
        while(cin>>a,a!="=")
        {
            r=r*10+num[a];
        }   
        //cout<<r<<endl;
        if(l==0&&r==0)
            break;
        printf("%d\n",l+r);
    }
    return 0;
 }