zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Java 泛型约束
    Java 单例模式
    Java中的Atomic包使用指南
    基数排序
    归并排序
    插入排序
    选择排序
    交换排序
    Java多线程 LockSupport
    Java并发控制:ReentrantLock Condition使用详解
  • 原文地址:https://www.cnblogs.com/littlepage/p/11300843.html
Copyright © 2011-2022 走看看