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 (<= 10^100^).
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
这题还是很简单的 但是我忘了 把0判断一下 其实这时候就体现出来了 do_while的好处了 17分
AC代码
#include<bits/stdc++.h>
using namespace std;
string num[20]={"zero","one","two","three","four","five","six","seven","eight","nine"};
stack<int>p;
int main()
{
ios::sync_with_stdio(false);
string s;
while(cin>>s){
while(!p.empty()) p.pop();
long long int sum=0;
for(int i=0;s[i];i++){
sum+=s[i]-'0';
}
if(sum==0){
cout<<"zero"<<endl;
return 0;
}
while(sum){
p.push(sum%10);
sum/=10;
}
int flag=0;
while(!p.empty()){
if(flag) cout<<" ";
cout<<num[p.top()];
p.pop();
flag=1;
}
cout<<endl;
}
return 0;
}