【题解】PATA-1005 Spell It Right

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.

样例输入

1
12345

样例输出

1
one five

提示

思路

水题,每一位加起来输出即可。

代码

查看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const int inf = 0x3f3f3f3f;
const int mxn = 1e3 + 5;

char s[mxn], p[][10] = {
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"
};

int main()
{
scanf("%s", s);
int n = strlen(s), ans = 0;

for(int i=0; i<n; i++){
ans += s[i]-'0';
}
sprintf(s, "%d", ans);
n = strlen(s);

for(int i=0; i<n; i++){
if(i) printf(" ");
printf("%s", p[s[i]-'0']);
}
printf("\n");
return 0;
}
_/_/_/_/_/ EOF _/_/_/_/_/