Spell It Right(PATA-1005)
题面
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.
输入
Each input file contains one test case. Each case occupies one line which contains an N (≤10^100).
输出
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.
样例输入
112345
样例输出
1one five
提示
无
思路
水题,每一位加起来输出即可。
代码
1const int inf = 0x3f3f3f3f;
2const int mxn = 1e3 + 5;
3
4char s[mxn], p[][10] = {
5 "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"
6};
7
8int main()
9{
10 scanf("%s", s);
11 int n = strlen(s), ans = 0;
12
13 for(int i=0; i<n; i++){
14 ans += s[i]-'0';
15 }
16 sprintf(s, "%d", ans);
17 n = strlen(s);
18
19 for(int i=0; i<n; i++){
20 if(i) printf(" ");
21 printf("%s", p[s[i]-'0']);
22 }
23 printf("\n");
24 return 0;
25}