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 <stack>
using namespace std;
void print(int n){
switch (n){
case 0:
cout<<"zero";
break;
case 1:
cout<<"one";
break;
case 2:
cout<<"two";
break;
case 3:
cout<<"three";
break;
case 4:
cout<<"four";
break;
case 5:
cout<<"five";
break;
case 6:
cout<<"six";
break;
case 7:
cout<<"seven";
break;
case 8:
cout<<"eight";
break;
case 9:
cout<<"nine";
break;
default:
break;
}
}
stack<int> t;
int main(){
// freopen("test.txt", "r", stdin);
string a;
int s=0;
cin>>a;
for (u_int i=0;i<a.length();++i){
s+=a[i]-'0';
}
if (s==0){
print(0);
return 0;
}
while (s>0){
t.push(s%10);
s/=10;
}
while (!t.empty()){
print(t.top());
t.pop();
if (!t.empty()) cout<<" ";
}
return 0;
}
本文介绍了一个简单的程序,该程序接收一个非负整数作为输入,并计算其所有位上的数字之和。之后,程序会将这个和的每个数字以英文单词的形式输出。示例中展示了如何通过C++实现这一功能。
1171

被折叠的 条评论
为什么被折叠?



