本题比较简单,利用数组储存大整数,每位数字求和后,再利用sprintf函数将数字返回为字符串,然后输出。代码如下:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
string numE[10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; //用字符串数组存对应的英文数字单词
while(cin>>s)
{
int sum=0;
for(int i=0;i!=s.length();++i) //求对应数位和
sum+=s[i]-'0';
char c[10000];
string cSum;
sprintf(c,"%d",sum); //将整型数据和转换为字符串
cSum=c;
for(int i=0;i!=cSum.length();++i) //输出对应英语数字
{
if(i<cSum.length()-1)
cout<<numE[cSum[i]-'0']<<' ';
else
cout<<numE[cSum[i]-'0']<<endl;
}
}
return 0;
}