A1005 Spell It Right (正确拼写)
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
结尾无空行
题意:
给出一串数字,将他们加起来,最后结果输出对应的英文拼写。
分析:
不知道为什么,整了很久,测试点4就是通不过。。。
又看了其它大佬的讲解,还是不明白。。。。
所以就劳烦哪位大神能不能看看我这个小菜鸡的代码哪里写错了啊,┭┮﹏┭┮
在下在这里谢过了❤
代码如下:
#include<cstdio>
#include<cstring>
char cp[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main(){
char in[110];
scanf("%s",&in);
int len=strlen(in);
int sum=0;
int i=0;
for(;i<len;i++){
sum=sum+(in[i]-'0');
}
if(sum==0) printf("zero");
else{
//再转
char res[10];
i=0;
while(sum!=0){
res[i++]=sum%10;
sum/=10;
}
len=strlen(res);
for(i=len-1;i>=0;i--){
printf("%s",cp[res[i]]);
if(i!=0) printf(" ");
}
}
return 0;
}