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
翻译:
给定一个非负整数N,你的任务是计算N的所有数字的总和,并用英语输出总和的每个数字。
输入格式:
每个输入文件包含一个测试用例。每个案例占用一行,其中包含N(≤10100).
输出规格:
对于每个测试用例,用英语单词在一行中输出总和的数字。两个连续单词之间必须有一个空格,但行尾不能有额外的空格。
代码:
#include <stdio.h>
#include <string.h>
int main()
{
char str[1000000];
scanf("%s",str);
int num=0;
for (int i=0;i<strlen(str);i++)
{
num+=(str[i] - '0');
}
char answer[100000];
sprintf(answer,"%d",num);
for (int i=0;i<strlen(answer);i++)
{
switch (answer[i])
{
case '1':printf("one");break;
case '2':printf("two");break;
case '3':printf("three");break;
case '4':printf("four");break;
case '5':printf("five");break;
case '6':printf("six");break;
case '7':printf("seven");break;
case '8':printf("eight");break;
case '9':printf("nine");break;
case '0':printf("zero");break;
}
if (i!=strlen(answer)-1)
printf(" ");
}
}