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
備注: sprintf系統函數用法:
int sprintf ( char * str, const char * format, ... );
功能:Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in the buffer pointed by str.
參數:
str
Pointer to a buffer where the resulting C-string is stored.
The buffer should be large enough to contain the resulting string.
format
C string that contains a format string that follows the same specifications as
format in
printf (see
printf for details).
...
(additional arguments)
Depending on the
format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a
format specifier in the
format string (or a pointer to a storage location, for
n).
There should be at least as many of these arguments as the number of values specified in the
format specifiers. Additional arguments are ignored by the function.
傳回值:
#include<stdio.h>
void PrintNumber(char s[])
{
int i;
for(i=0;s[i]!='\0';i++)
{
switch(s[i])
{
case '0':printf("%s","zero");break;
case '1':printf("%s","one");break;
case '2':printf("%s","two");break;
case '3':printf("%s","three");break;
case '4':printf("%s","four");break;
case '5':printf("%s","five");break;
case '6':printf("%s","six");break;
case '7':printf("%s","seven");break;
case '8':printf("%s","eight");break;
case '9':printf("%s","nine");break;
}
if(s[i+1]=='\0')
break;
printf(" ");
}
}
int main()
{
int sum, i;
char s[200];
char s_sum[100];
scanf("%s",s);
sum = 0;
for(i=0;s[i]!='\0';i++)
sum += s[i]-'0';
sprintf(s_sum, "%d", sum);
PrintNumber(s_sum);
return 0;
}