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
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main() {
vector<vector<string> >q;//定义向量q为字符型
q.resize(101);//定义q大小为101
q.clear();
stack <string>s;//定义字符型栈s
int sum=0;
string n;
cin>>n;
for(int i=0;i<n.size();i++)
sum+=n[i]-'0';//将输入转为整型
q[0].push_back("zero");
q[1].push_back("one");
q[2].push_back("two");
q[3].push_back("three");
q[4].push_back("four");
q[5].push_back("five");
q[6].push_back("six");
q[7].push_back("seven");
q[8].push_back("eight");
q[9].push_back("nine");
if(sum==0)
s.push(q[0][0]);//当和为0时,把'zero'入栈
else{
while(sum!=0){//把和的每一位入栈
s.push(q[sum%10][0]);
sum/=10;
}
}
int l=0;
while(s.empty()!=1){//在栈不空的情况下,输出每一位
l++;
if(l==1)
cout<<s.top();
else
cout<<' '<<s.top();
s.pop();
}
cout<<endl;
return 0;
}