杭电ACM 1228 A + B

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

这道题没有算法,有点罗嗦~~其实就是字符串转换成int

出于无奈,用了goto语句,但最后确实通过了~~幸运~~

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

int chan(string a,string b){
	int num=0;
	if(a=="zero")
		  num+=0;
	if(a=="one") 
		  num+=10;
    if(a== "two")
		  num+=20;
	if(a=="three")
		  num+=30;
    if(a=="four") 
		  num+=40;
    if(a== "five") 
		  num+=50;
    if(a== "six")
		  num+=60;
    if(a== "seven")
		  num+=70;
    if(a=="eight")
		  num+=80;
    if(a== "nine")
		  num+=90;         
	if(b=="zero")
		  num+=0;
	if(b=="one") 
		  num+=1;
    if(b== "two")
		  num+=2;
	if(b=="three")
		  num+=3;
    if(b=="four") 
		  num+=4;
    if(b== "five") 
		  num+=5;
    if(b== "six")
		  num+=6;
    if(b== "seven")
		  num+=7;
    if(b=="eight")
		  num+=8;
    if(b== "nine")
		  num+=9;         
	return num;
	
}
int main(){
   string a,b,c,d,e,f;
 star:  cin>>a>>b;
   if(b=="+"){
   	b=a;
    a="0";
	c="+";   	
   }
   else cin>>c;
   cin>>d>>e;
   if(e=="="){
   	e=d;
    d="0";
   	f=e;
   	
   }
   else cin>>f;
   int fir=chan(a,b);
   int sec=chan(d,e);
   while(fir==0&&sec==0)
   return 0;
   cout<<fir+sec<<endl;
   goto star;
   return 0;   
}


你可能感兴趣的:(杭电ACM 1228 A + B)