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
简单的模拟类型题,没什么好说的。
代码
1 #include <stdio.h>
2 #include <string.h>
3
4 int main()
5 {
6 char str[];
7 char* const_str[] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
8 while(gets(str)){
9 int n = strlen(str);
int i = ;
int sum = ;
for (;i<n;++i){
sum = sum + str[i] - '';
}
sprintf(str,"%d",sum);
n = strlen(str);
printf("%s",const_str[str[]-'']);
for(i=;i<n;++i){
printf(" %s",const_str[str[i]-'']);
}
printf("\n");
}
return ;
}