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
唯一注意的是对总和数字的处理。因为不像进制转化中从低位到高位,这道题需要从高位到低位。
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
char str[105];
char word[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int t=0,i,a,n,b;
b=scanf("%s",str);
for (i=0;i<strlen(str);i++)
t=t+str[i]-'0';
b=0;
a=1000;
if (t==0) {
printf("%s\n",word[0]);
return 0;
}
while (a>0){
n=t/a;
if (n==0&&b==0) {
a=a/10;
continue;
}
b=1;
t=t%a;
a=a/10;
if (a!=0) printf("%s ",word[n]);
else printf("%s\n",word[n]);
}
return 0;
}