您的位置:首页 > 其它

HDOJ1228 ( A + B ) 【字符串处理】

2012-05-13 10:56 369 查看
[align=center]Problem : 1228 ( A + B ) Judge Status : Accepted
RunId : 5937463 Language : C Author : qq1203456195
Code Render Status : Rendered By HDOJ C Code Render Version 0.01 Beta
[/align]
#include <stdio.h>
int find(char a,char b)
{
int n;
switch(a)
{
case 'z':
n=0;
break;
case 'o':
n=1;
break;
case 't':
n=((b=='w')?2:3);
break;
case 'f':
n=((b=='o')?4:5);
break;
case 's':
n=((b=='i')?6:7);
break;
case 'e':
n=8;
break;
case 'n':
n=9;
break;
}
return n;
}
int getnum()
{
char str[10];
int t;
scanf("%s",str);
t=find(str[0],str[1]);
scanf("%s",str);
if(str[0]=='+')
return t;
else
{
if(str[0]=='=')
return t;
else
{
t*=10;
t+=find(str[0],str[1]);
scanf("%s",str);
return t;
}
}
}

int main()
{
int a,b;
while (1)
{
a=getnum();
b=getnum();
if(a||b)
printf("%d\n",a+b);
else
break;
}
return 0;
}

#include <stdio.h>
int find(char a,char b)
{
int n;
switch(a)
{
case 'z':
n=0;
break;
case 'o':
n=1;
break;
case 't':
n=((b=='w')?2:3);
break;
case 'f':
n=((b=='o')?4:5);
break;
case 's':
n=((b=='i')?6:7);
break;
case 'e':
n=8;
break;
case 'n':
n=9;
break;
}
return n;
}
int getnum()
{
char str[10];
int t;
scanf("%s",str);
t=find(str[0],str[1]);
scanf("%s",str);
if(str[0]=='+')
return t;
else
{
if(str[0]=='=')
return t;
else
{
t*=10;
t+=find(str[0],str[1]);
scanf("%s",str);
return t;
}
}
}

int main()
{
int a,b;
while (1)
{
a=getnum();
b=getnum();
if(a||b)
printf("%d\n",a+b);
else
break;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: