因为数据和在0-900之间,故可以采用一种取巧的方法,直接分成0-9,10-99,100-900三段输出
AC代码如下
#include <iostream>
using namespace std;
const int max_n = 110;
char N[max_n];
const char *num[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main (){
int sum = 0;
int k = 0;
scanf("%s",N);
for(int i = 0; N[i]!='\0'; i++){
sum+=(N[i]-'0');
}
if(sum>=100){
printf("%s %s %s",num[sum/100],num[(sum/10)%10],num[sum%10]);
}
else if(sum>=10){
printf("%s %s",num[sum/10],num[sum%10]);
}
else{
printf("%s",num[sum%10]);
}
return 0;
}