HDU 1228

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

依然是水题,就是写的多而已,据说是浙大研究生复试题,就是练习速度的。头文件写多了。。。。

代码如下:

#include  < iostream >
#include 
< algorithm >
#include 
< string >
#include 
< set >
#include 
< cmath >
#include 
< iomanip >
using   namespace  std;

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


int  main()
{
    
string str1,str2,str3,str4,str5,str6;
    
int s1,s2;
    
while(cin>>str1>>str2>>str3>>str4)
    
{
        
if(str1=="zero" && str3=="zero")
            
break;
        
if(str2!="+")
        
{
            s1
=change(str1)*10+change(str2);
            cin
>>str5;
            
if(str5!="=")
            
{
                s2
=change(str4)*10+change(str5);
                cin
>>str6;
            }

            
else
                s2
=change(str4);
        }

        
else
        
{
            s1
=change(str1);
            
if(str4!="=")
            
{
                s2
=change(str3)*10+change(str4);
                cin
>>str5;
            }

            
else
                s2
=change(str3);
        }

        cout
<<s1+s2<<endl;

    }

    
return 0;
}

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