果枫-国峰

hdu 1228 A+B

题意:如题。

 

ac代码:

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

int change(string ch)
{
    /*switch(ch)
    {
    case "zero":return 0;
    }*/
    
    if(ch=="zero")
        return 0;
    if(ch=="one")
        return 1;
    if(ch=="two")
        return 2;
    if(ch=="three")
        return 3;
    if(ch=="four")
        return 4;
    if(ch=="five")
        return 5;
    if(ch=="six")
        return 6;
    if(ch=="seven")
        return 7;
    if(ch=="eight")
        return 8;
    if(ch=="nine")
        return 9;
    
}

int main()
{
    string ch;
    
    while(cin>>ch)
    {
        int a,b=0;
        a=change(ch);
        cin>>ch;
        int foat=0;
        while(ch!="=")
        {
            
            if(ch=="+")
            {
                foat=1;
                
            }
            else
            {
                if(foat==0)
                    a=a*10+change(ch);
                else
                {
                    if(b==0)
                        b=change(ch);
                    else
                        b=b*10+change(ch);
                }
            }
            cin>>ch;
        }
        int sum=a+b;
        if(a==0&&b==0)break;
        cout<<sum<<endl;
    }
    return 0;
    
}
/*
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =

*/

 

posted on 2012-09-06 16:26  果枫-国峰  阅读(233)  评论(0编辑  收藏  举报

导航