代码:
#include<cstdio> #include<cstring> using namespace std; char s[10][20]; int main() { strcpy(s[0],"zero");//对字符数组赋值 strcpy(s[1],"one"); strcpy(s[2],"two"); strcpy(s[3],"three"); strcpy(s[4],"four"); strcpy(s[5],"five"); strcpy(s[6],"six"); strcpy(s[7],"seven"); strcpy(s[8],"eight"); strcpy(s[9],"nine"); char ss[105]; while(scanf("%s",ss)==1) { int ans=0; int len=strlen(ss); if(strcmp(ss,"0")==0) { printf("zero\n"); continue; } for(int i=0;i<len;i++) { ans+=(ss[i]-'0'); } int a[105]; int k=0; while(ans) { int r=ans%10; a[k]=r; k++; ans=ans/10; } for(int i=k-1;i>=0;i--) { if(i==0) printf("%s\n",s[a[i]]); else printf("%s ",s[a[i]]); } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-16 07:01:29