1005. spell it right (20) Time Limit 400 MS
The memory limit is 32000 kb.
Code length limit: 16000 B
Criterion author 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:
12345
Sample output:
one five
#include<iostream>#include <string>#include <stack>using namespace std;string getString(int n){ switch(n) { case 0:return "zero";break; case 1:return "one";break; case 2:return "two";break; case 3:return "three";break; case 4:return "four";break; case 5:return "five";break; case 6:return "six";break; case 7:return "seven";break; case 8:return "eight";break; case 9:return "nine";break; }}int main(){ string str; string::iterator it; int flag=false; stack<int> s; int sum=0; cin>>str; for (it=str.begin();it!=str.end();it++) sum += (*it)-'0'; while(sum) { s.push(sum%10); sum/=10; } if (s.empty()) cout<<"zero"; while(!s.empty()) { if (flag) cout<<" "; else flag = true; cout<<getString(s.top()); s.pop(); } cout<<endl; //system("pause"); return 0;}