A+B(HDOJ)

http://acm.hdu.edu.cn/showproblem.php?pid=1228

模拟类字符串处理问题

#include <cstdlib>
#include <iostream>

using namespace std;

string num[]={"zero","one","two","three","four","five","six","seven","eight","nine"};

int search(string a)
{
    for(int i=0;i<10;i++)
    {
        if(num[i]==a)
        return i;
    }
}

int main(int argc, char *argv[])
{
    int result1=0,result2=0;
    string tmp;
    while(true)
    {
        while(cin>>tmp&&tmp!="+")
        {
            //cout<<tmp<<endl;
            
            //if(tmp=="=")
            //result=0;  
            //cout<<search(tmp)<<endl;
            result1 = result1*10+search(tmp);
            //cout<<result1<<"result1"<<endl;        
            
        }
        while(cin>>tmp&&tmp!="=")
        {
            result2 =result2*10+search(tmp);
        }
        //cout<<result2<<"result2"<<endl;
        if(result1==0&&result2==0)
        break;
        cout<<result1+result2<<endl;
        result1=0;
        result2=0;
    }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}



你可能感兴趣的:(A+B(HDOJ))