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 (≤10
100
).
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<cstdio>
#include<cstring>
int main()
{
char num[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
char in[102];//100次方 101位 +1位‘/0’
int out[3];
scanf("%s",in);
int sum=0;
int l=strlen(in);
for(int i=0;i<l;i++)
sum=sum+in[i]-'0';
int len=0;
do{
out[len++]=sum%10;
sum=sum/10;
}while(sum!=0);
for(int i=len-1;i>=0;i--)//总会忘记--浪费时间找错
{
printf("%s",num[out[i]]);
if(i!=0)
printf(" ");
}
return 0;
}