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;
    }
  • 相关阅读:
    ios实现下拉刷新,上拉加载
    ios实现瀑布流
    ios收货地址三级联动选择
    ios仿淘宝管理收货地址demo
    引用传值
    继承小结
    is操作符和as操作符
    抽象类和object类
    重写基类
    派生
  • 原文地址:https://www.cnblogs.com/littlepage/p/11300843.html
Copyright © 2011-2022 走看看