# 1005. Spell It Right (20)

66人阅读 评论(0)

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;
}
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：7873次
• 积分：507
• 等级：
• 排名：千里之外
• 原创：45篇
• 转载：1篇
• 译文：0篇
• 评论：1条