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 }

 

转载于:https://www.cnblogs.com/zjushuiping/archive/2012/05/30/2526963.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值