Spell It Right

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

Input Specification:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

Sample Input:
12345
Sample Output:
one five


 1 /* 
 2  * File:   main.cpp
 3  * Author: zjushuiping
 4  *
 5  * Created on 2012年4月11日, 上午12:13
 6  */
 7 
 8 #include <cstdlib>
 9 #include <iostream>
10 #include <cstdio>
11 #include <vector>
12 #include <cmath>
13 #include <cstring>
14 #include <cctype>
15 #include <list>
16 #include <deque>
17 #include <stack>
18 #include <queue>
19 #include <map>
20 #include <set>
21 #include <string>
22 #include <algorithm>
23 
24 
25 using namespace std;
26 
27 
28 
29 
30 
31 
32 /*
33  * 
34  */
35 
36 
37 char str[100+4];
38 
39 
40 
41 char mp[10][15]={"zero","one","two","three","four","five","six","seven","eight","nine"};
42 
43 
44 
45 int main(int argc, char** argv) {
46 
47 
48 
49     gets(str);
50     int i;
51     int len=strlen(str);
52 
53     int sum=0;
54 
55 
56     for(i=0;i<len;i++)
57     {
58         sum+=str[i]-'0';
59 
60 
61     }
62 
63 
64     char tempstr[100];
65 
66     sprintf(tempstr,"%d",sum);
67 
68     int tempstr_len=strlen(tempstr);
69 
70 
71     int tag=0;
72 
73 
74     for(i=0;i<tempstr_len;i++)
75     {
76         if(tag==0)
77         {
78             printf("%s",mp[tempstr[i]-'0']);
79             tag=1;
80 
81         }
82         else
83         {
84             printf(" %s",mp[tempstr[i]-'0']);
85 
86         }
87     }
88 
89     puts("");
90 
91  
92     return 0;
93 }

 

posted @ 2012-05-30 21:36  cseriscser  阅读(145)  评论(0编辑  收藏  举报