http://pat.zju.edu.cn/contests/pat-a-practise/1005
1.数字拆分。
2.转为单词,用map,映射。
3.边缘数据,仅仅一个0。
#include <stdio.h>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#define SIZE 110
using namespace std;
char map[][10]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("E:\\in.txt", "r" , stdin);
#endif
char s[SIZE];
while(scanf("%s", s) != EOF)
{
int i=0, sum=0;
while(s[i] != '\0')
{
int t = s[i] - '0';
sum += t;
i++;
}
int buf[SIZE], j=0;
while(sum > 0)
{
int t = sum % 10;
buf[j++]=t;
sum = sum/10;
}//分离每一位,先得个位
if(j == 0) //sum = 0时,仅一个0
{
printf("zero\n");
continue;
}
while(--j>=0)
{
//printf("%d", buf[j]);
printf("%s", map[buf[j]]);
if(j != 0)
printf(" ");
else
printf("\n");
}//print
}//while
return 0;
}