PAT 1005

来源:互联网 发布:java windows换行符 编辑:程序博客网 时间:2024/06/13 15:42

1005. Spell It Right (20)

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>#include <string.h>using namespace std;#define max 100char input[max];int main(){stack<int> s;int i,t,len,sum=0;    cin>>input;len=strlen(input);for(i=0;i<len;i++){t=input[i]-'0';sum+=t;}while(sum/10!=0)//sum>10{t=sum%10;//个位sum=sum/10;s.push(t);//入栈}s.push(sum);while(!s.empty()){t=s.top();s.pop();if(t==1){cout<<"one";}if(t==2){cout<<"two";}if(t==3){cout<<"three";}if(t==4){cout<<"four";}if(t==5){cout<<"five";}if(t==6){cout<<"six";}if(t==7){cout<<"seven";}if(t==8){cout<<"eight";}if(t==9){cout<<"nine";}if(t==0){cout<<"zero";}if(!s.empty()){cout<<" ";}else{cout<<endl;}}    return 0;}

 
1 0