1005. Spell It Right (20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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
1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <queue> 5 #include <stack> 6 #include <iostream> 7 using namespace std; 8 string digits[15]={"zero","one","two","three","four","five","six","seven","eight","nine"}; 9 int main(){ 10 string ss; 11 int sum=0,i=0,csum=0; 12 cin>>ss; 13 while(i<ss.length()){ 14 sum+=ss[i++]-'0'; 15 } 16 if(!sum){ 17 cout<<digits[sum]<<endl; 18 return 0; 19 } 20 stack<string> s; 21 while(sum){ 22 s.push(digits[sum%10]); 23 sum/=10; 24 } 25 cout<<s.top(); 26 s.pop(); 27 while(!s.empty()){ 28 cout<<" "<<s.top(); 29 s.pop(); 30 } 31 return 0; 32 }