九度OJ 1010:计算A+B【字符串和数组】

/*========================================================================
题目1010:A + B
时间限制:1 秒内存限制:32 兆
题目描述:
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
输入:
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
输出:
对每个测试用例输出1行,即A+B的值.
样例输入:
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
样例输出:
3
90
96
来源:
2005年浙江大学计算机及软件工程研究生机试真题
==========================================================================*/
 #include<stdio.h>
#include<string.h>
char a[][]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int fun(char t[])
{
int i=;
while(t[i]!='\0')
{
if(t[i]>='A'&&t[i]<='Z')
{
t[i]=t[i]+;
}
i++;
}
for(i=;i<;i++)
{
if(strcmp(t,a[i])==) return i;
}
}
int main()
{
int a,b,c;
char t[];
freopen("1010.in","r",stdin);
while(scanf("%s",t)!=EOF)
{
a=;
while(strcmp(t,"+")!=)
{
c=fun(t);
a=a*+c;
scanf("%s",t);
} b=;
scanf("%s",t);
while(strcmp(t,"=")!=)
{
c=fun(t);
b=b*+c;
scanf("%s",t);
}
if(a!=&&b!=)
printf("%d\n",a+b);
}
return ;
}

网上提交时记得把freopen给删掉。

上一篇:SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑


下一篇:通过SectionIndexer实现微信通讯录