zoukankan      html  css  js  c++  java
  • PAT 1005 Spell It Right

    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<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    vector<string> vec={{"zero"},{"one"},{"two"},{"three"},{"four"},{"five"},{"six"},{"seven"},{"eight"},{"nine"}};
    
    vector<int> temp;
    
    
    int main(){
        string s;
        cin >> s;
        ll sum = 0;
        for(int i=0;i < s.size();i++){
            sum += (s[i]-'0');
        }
        if(sum == 0) cout << vec[0];
        while(sum){
            temp.push_back(sum%10);
            sum = sum/10;
        }
        for(int i=temp.size()-1;i>=0;i--){
            cout << vec[temp[i]];
            if(i) cout << " ";
        }
    
    
        return 0;
    }

    sum = 0的情况要注意,不会进入循环。

  • 相关阅读:
    程序员学习提高必看的一篇文章
    SpringAOP拦截器的代理机制
    springboot03_RabbitMQ
    Docker_02
    Docker_01
    Redis_02
    Redis_01
    关于Linux下内存和Swap
    密码学DAY2
    密码学DAY1_02
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10674575.html
Copyright © 2011-2022 走看看