题目链接:https://www.patest.cn/contests/pat-a-practise/1005
题目大意:对正整数N,将其各位数字相加得到和sum,然后输出sum的每位数字的英文单词
代码如下:
#include<iostream>
using namespace std;
char num[10][6]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main(){
char str[102];
cin>>str;
int sum=0;
for(int i=0;str[i]!='\0';i++){
sum+=(str[i]-'0');
}
int result[4];
int len=0;
while(sum){
result[len++]=sum%10;
sum/=10;
}
cout<<num[result[len-1]];
if((len-1)!=0){
for(int i=len-2;i>=0;i--){
cout<<" "<<num[result[i]];
}
}
return 0;
}