您的位置:首页 > 编程语言 > C语言/C++

1005. Spell It Right (20)(C++)

2018-02-26 13:38 507 查看
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<cstdio>
#include<string>
#include<stack>
#include<algorithm>
using namespace std;
int main(){
string e[11]={"zero","one","two","three","four","five","six","seven","eight","nine"};
string s;
stack<int>a;
cin>>s;
int sum=0;
for(int i=0;i<s.length();i++){
sum+=s[i]-'0';
}
if(sum==0)
cout<<"zero";
while(sum!=0){
int x=sum%10;
a.push(x);
sum/=10;
}
int flag=0;
while(!a.empty()){
int x;
x=a.top();
a.pop();
if(flag==1)
cout<<' ';
if(flag==0)
flag=1;
cout<<e[x];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: