思路:
用字符数组来存储这个大整数
由它的范围可以知道每一项相加都不会大于int的最大值,所以可以用int存储最后各位相加的值
将sum值输入到一个字符数组,然后用另一个数组映射对应的字符串即可
#include <cstdio> using namespace std; int main() { char num[111]={‘\0‘}; scanf("%s",num); int sum=0; for(int i=0;num[i]!=‘\0‘;i++) { sum+=(num[i]-‘0‘); } //printf("%d\n",sum); const char* res[]={"zero","one","two","three","four","five","six","seven","eight","nine"}; char tem[10]={‘\0‘}; sprintf(tem,"%d",sum); //printf("%s\n",tem); for(int i=0;tem[i]!=‘\0‘;i++) { tem[i+1]==‘\0‘? printf("%s",res[tem[i]-‘0‘]):printf("%s ",res[tem[i]-‘0‘]); } printf("\n"); return 0; }