题目描述
读入两个小于100的正整数A和B,计算A+B,注意: A+B的每一位由对应的英文字母给出。
输入
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为zero时输入结束,相应的结果不要输出.
输出
对每个测试用例输出1行,即A+B的值.
样例输入
one + two = three four + five six = zero + zero =
样例输出
3 90
AC Code
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 1000 + 10;
int a[MAXN];
string num[10]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
string s;
int getNum(string &a){
for(int i=0; i<10; ++i){
if(a==num[i]) return i;
}
return -1; //means error
}
int main(){
freopen("C:\\Users\\Ambition\\Desktop\\in.txt","r",stdin);
int a=0, b=0, flag1=0, flag2=0;
while(cin>>s){
if(!flag1){
if(s!="+" )
a=a*10+getNum(s);
else
flag1=1;
} else {
if(s!="=")
b=b*10+getNum(s);
else
flag2=1;
}
if(a==0 && b==0) break;
if(flag1 && flag2){
printf("%d\n", a+b);
a=b=0;
flag1=flag2=0;
}
}
return 0;
}