输出输入的n位整数的每一位之和的英文,注意一下输出的数组嵌套。
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 int main(){ 5 string num[10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; 6 string input; 7 cin>>input; 8 long long sum=0,dig[1000]; 9 int len=input.length(); 10 for(int i=0;i<len;i++) sum+=input[i]-'0'; 11 int con=0; 12 while(sum!=0){ 13 dig[con]=sum%10; 14 sum=sum/10; 15 con+=1; 16 } 17 cout<<num[dig[con-1]]; 18 for(int i=con-2;i>=0;i--){ 19 cout<<' '<<num[dig[i]]; 20 } 21 return 0; 22 }