ACM1228_STL的应用

#include<iostream>
#include<string>
#include<map>
using namespace std;
 
map<string ,int> mp;
 
void setMap()
{
    mp["zero"] = 0;
    mp["one"] = 1;
    mp["two"] = 2;
    mp["three"] = 3;
    mp["four"] = 4;
    mp["five"] = 5;
    mp["six"] = 6; 
    mp["seven"] = 7;
    mp["eight"] = 8;
    mp["nine"] = 9;
}
int main ()
{
    setMap ();
    int sum;
    string a,b;
    string filter;
    while(cin>>a)
    {
        sum=0;
        cin>>b;
        if(b!="+")
        {
            sum+=mp[a]*10+mp[b];
            cin>>filter;
        }
        else
        {
            sum+=mp[a];
        }
        cin>>a>>b;
        if(b!="=")
        {
            sum+=mp[a]*10+mp[b];
            cin>>filter;
        }
        else
        {
            sum+=mp[a];
        }
        if(sum == 0)
        {
            break;
        }
        else
        {
            cout<<sum<<endl;
        }
    }
    return 0; 
}

 

posted @ 2013-07-12 13:07  Talbot3  阅读(238)  评论(0编辑  收藏  举报