原题:
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
题意:
.......
就是英文输入数字计算和
题解:
这题,没啥好解的啊
就是字符串输入输入一直到加号
然后输入输入一直到等号
因为给出的是英文数字而且没有位数
所以要转化一下然后计算输出就行了
到两个0的时候停止
代码:AC
#include<iostream>
#include<cstring>
using namespace std;
char number[11][11]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int nu(char *s)
{
int i;
for(i=0;i<10;i++)
{
if(strcmp(s,number[i])==0)
return i;
}
return -1;
}
int main()
{
char s[11];
int a=0,b=0;
while(scanf("%s",s))
{
while(strcmp(s,"+")==1)
{
a=a*10+nu(s);
scanf("%s",s);
}
scanf("%s",s);
while(strcmp(s,"=")==1)
{
b=b*10+nu(s);
scanf("%s",s);
}
if(a+b==0)
return 0;
else
cout<<a+b<<endl;
a=b=0;
}
return 0;
}