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
编译软件:visual studio
编译语言:c语言
参考代码:
#include<cstdio>
#include<cstring>
char num[10][10] = { "zero","one","two","three","four","five","six","seven","eight","nine" };
char s[111];
int digit[10];
int main()
{
gets_s(s);
int len = strlen(s);
int sum = 0, numlen = 0;
for (int i = 0; i < len; i++)
{
sum += (s[i] - '0');
}
if (sum == 0) {
printf("%s", num[0]);
}
else
{
while (sum != 0)
{
digit[numlen++] = sum % 10;
sum /= 10;
}
}
for (int i = numlen - 1; i >= 0; i--)
{
printf("%s", num[digit[i]]);
if (i != 0) printf(" ");
}
return 0;
}
注:要注意特殊数据0,应该直接特判输出0