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
#include <stdio.h>
#include <string.h>
int main()
{
char eng[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
char a[110];
gets(a);
int sum=0;
for(int i=0;i<strlen(a);i++){
sum += a[i]-'0';
}
int len=0;
int res[5]={0};
do{
res[len++]=sum%10;
sum/=10;
}while(sum!=0);
for(int i=len-1;i>=0;i--){
printf("%s",eng[res[i]]);
if(i!=0) printf(" ") ;
}
return 0;
}
本文介绍了一个程序设计挑战,要求将输入的非负整数的各位数字相加,并将和的每一位用英文单词表示。通过读取字符串形式的大整数,逐位计算其数值总和,再将总和的每位数字转换为英文单词输出。此题目考察了字符串操作、数学计算及数组应用等技能。
389

被折叠的 条评论
为什么被折叠?



