# 1005. Spell It Right (20)

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

AC代码：

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char number[10][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
char result[10][10] = {0};
int main(int argc, char* argv[])
{
int sum = 0, i;
char num[1000] = {0};
scanf("%s", num);
for(i = 0; i < strlen(num); i++)
{
sum += num[i] - '0';
}
if(sum == 0)
{
printf("zero\n");
}
else{
i = 0;
while(sum){
strcpy(result[i++], number[sum%10]);
sum = sum / 10;
}
for(i = i - 1;i >= 0 ; i--)
{
if(0 == i)
printf("%s\n", result[0]);
else
printf("%s ", result[i]);
}
}
system("pause");
return 0;
}
• 本文已收录于以下专栏：

举报原因： 您举报文章：1005. Spell It Right (20) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)