HDU 1228 ( A + B )

Problem : 1228 ( A + B )     Judge Status : Accepted
RunId : 5729530    Language : C++    Author : ssun
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta

#include<iostream>
#include<string>
using namespace std;

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

int main()
{
    int a,a1,a2,b,b1,b2,i;
    string s1,s2;
    while(true)
    {
        a1=a2=b1=b2=0;
        cin>>s1>>s2;
        for(i=0; i<=9; i++)
        {
            if(s1==ss[i]) 
            {
                a1 = i;
                break;
            }
        }
        if(s2!="+") 
        {
            for(i=0; i<=9; i++)
            {
                if(s2==ss[i]) 
                {
                    a2 = i;
                    break;
                }
            }
            a = a1*10 + a2;
            cin>>s1;
        }
        else a = a1;
        cin>>s1>>s2;
        for(i=0; i<=9; i++)
        {
            if(s1==ss[i]) 
            {
                b1 = i;
                break;
            }
        }
        if(s2!="=") 
        {
            for(i=0; i<=9; i++)
            {
                if(s2==ss[i]) 
                {
                    b2 = i;
                    break;
                }
            }
            b = b1*10 + b2;
            cin>>s1;
        }
        else b = b1;
        
        if(a==0 && b==0) break;
        cout<<a+b<<endl;
    }

}


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