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的情况要注意,不会进入循环。

  • 相关阅读:
    常用工具类
    手机端加载中
    jeecg的各种坑
    资源
    idea 破解后无法启动,我的配置文件搞错了
    eclipse xml 报某某.xsd找不到
    linux上部署svn服务器
    苹果手机微信浏览器无法通过post提交form数据
    %%%
    AtCoder arc060_d
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10674575.html
Copyright © 2011-2022 走看看