1005 Spell It Right (20 分)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Input Specification:
Each input file contains one test case. Each case occupies one line which contains an N (≤10100).
Output Specification:
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
Sample Input:
12345
Sample Output:
one five
给定一个非负整数n,求出数位之和,并用英语表示这个总和的每一位。
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string s[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
string a,b;
int i,j,k,len,cnt=0;
cin>>a;
len=a.length();
if(len==1&&a[0]=='0')
cout<<s[0]<<endl;
else
{
for(i=0;i<len;i++)
{
cnt+=(a[i]-'0');
}
while(cnt>0)
{
b+=(cnt%10+'0');
cnt/=10;
}
for(i=b.length()-1;i>=0;i--)
{
if(i==0)
cout<<s[b[i]-'0']<<endl;
else
cout<<s[b[i]-'0']<<" ";
}
}
return 0;
}