hdu 1228(英文A+B)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1228

题目分析:代码比较给力,自己倒是想不到:

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;
char num[10][6]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int search(char ch[]){
	int i;
	for(i=0;i<10;i++){
		if(strcmp(ch,num[i])==0)
			break;
	}
	return i;
}
int main(){
	char count[10];
	int a,b;
	while(1){
		a=0;
		while(scanf("%s",count)&&strcmp(count,"+")!=0)
			a=a*10+search(count);
		b=0;
		while(scanf("%s",count)&&strcmp(count,"=")!=0)
			b=b*10+search(count);
		if(a==0&&b==0) return 0;
		else
			printf("%d\n",a+b);
	}
	return 0;
}


你可能感兴趣的:(hdu 1228(英文A+B))