cjweffort

博客园 首页 联系 订阅 管理
// 1005. Spell It Right.cpp: 主项目文件。

#include "stdafx.h"
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <iostream>
using namespace std;

map<int,string> cmap;

void operate(int sum){
	if(sum==0){
		puts("zero");
		return;
	}
	int aa[4],cnt=0;
	memset(aa,0,sizeof(aa));
	while(sum){
		aa[cnt++]=sum%10;
		sum/=10;
	}
	for(int i=cnt-1;i>=0;i--){
		if(i!=cnt-1)
			cout<<" ";
		cout<<cmap[aa[i]];
	}
	cout<<endl;
}

int main()
{
    const int N=103;
	char str[N];
	cmap[0]="zero";cmap[1]="one";cmap[2]="two";cmap[3]="three";
	cmap[4]="four";cmap[5]="five";cmap[6]="six";cmap[7]="seven";
	cmap[8]="eight";cmap[9]="nine";
	while(gets(str)){
		int sum=0;
		for(int i=0;str[i];i++)
			sum+=str[i]-'0';
		operate(sum);
	}
    return 0;
}

posted on 2013-03-14 08:08  cjweffort  阅读(184)  评论(0编辑  收藏  举报