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:
12345Sample 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]; } }
相关文章推荐
- 【c++】PAT (Advanced Level) 1005. Spell It Right (20)
- 【PAT甲级】【C++】1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT 甲级 1005. Spell It Right (20) 【字符串】
- PAT - 甲级 - 1005. Spell It Right (20)
- 浙江大学PAT上机题解析之1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 【PAT甲级】1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)水题
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT 1005. Spell It Right(20)
- PAT 1005. Spell It Right (20)
- PAT (Advanced) 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT-1005 Spell It Right (20)
- PAT (Advanced Level) Practise 1005 Spell It Right (20)
- 1005.Spell It Right (20)
- PAT1005. Spell It Right (20)