题目描述
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.#
输入格式
Each input file contains one test case. Each case occupies one line which contains an N (≤10^100).
输出格式
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.
输入样例
12345
输出样例
one five
AC代码
#include <iostream>
#include <string>
#include <stack>
#include <algorithm>
using namespace std;
string s[10] = {"zero","one","two","three","four",
"five","six","seven","eight","nine"};
int main(){
string num;
cin>>num;
int sum = 0;
for(int i = 0; i < num.size(); i++){
sum += num[i] - '0';
}
int a = sum, b;
stack<string> n;
if(a == 0) cout<<"zero";
else{
while(a != 0){
b = a % 10;
n.push(s[b]);
a = a / 10;
}
int i = 0;
while(!n.empty()){
if(i == 0)
cout<<n.top();
else cout<<" "<<n.top();
n.pop();
i++;
}
}
return 0;
}