PAT Advanced 1005 Spell It Right (20 分)

PAT Advanced 1005 Spell It Right (20 分)
强烈推介IDEA2021.1.3破解激活,IntelliJ IDEA 注册码,2021.1.3IDEA 激活码  

大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说PAT Advanced 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 (≤).

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>
using namespace std;
int main() {
    string s;
    cin>>s;
    stack<int> sta;
    int sum=0,tmp;
    for(int i=0;i<s.length();i++){
        sum+=(s[i]-'0');
    }
    while(sum!=0){
        sta.push(sum%10);
        sum/=10;
    }
    if(sta.empty()) cout<<"zero";
    while(!sta.empty()){
        tmp=sta.top();
        sta.pop();
        switch(tmp){
            case 0:cout<<"zero";break;
            case 1:cout<<"one";break;
            case 2:cout<<"two";break;
            case 3:cout<<"three";break;
            case 4:cout<<"four";break;
            case 5:cout<<"five";break;
            case 6:cout<<"six";break;
            case 7:cout<<"seven";break;
            case 8:cout<<"eight";break;
            case 9:cout<<"nine";break;
            case 10:cout<<"ten";break;
        }
        if(sta.size()!=0) cout<<" ";
    }
    system("pause");
    return 0;
}

 

转载于:https://www.cnblogs.com/littlepage/p/11300843.html

本文来源weixin_30595035,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/29523

发表评论