• 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;
    const int maxn=10010;
    int nums[maxn];
    void trance(int m){
        if(m==0){
            printf("zero");
        }
        else if(m==1){
            printf("one");
        }
        else if(m==2){
            printf("two");
        }
        else if(m==3){
            printf("three");
        }
        else if(m==4){
            printf("four");
        }
        else if(m==5){
            printf("five");
        }
        else if(m==6){
            printf("six");
        }
        else if(m==7){
            printf("seven");
        }
        else if(m==8){
            printf("eight");
        }
        else if(m==9){
            printf("nine");
        }
    }
    int main(){
        string n;
        cin>>n;
        if(n=="0"){
            printf("zero
    ");
            return 0;
        }
        long long sum=0;
        for(int i=0;i<n.size();i++){
            sum+=n[i]-'0';
        }
        int i=0;
        while(sum>0){
            nums[i]=sum%10;
            sum/=10;
            i++;
        }
        for(int j=i-1;j>=0;j--){
            trance(nums[j]);
            if(j>0){
                printf(" ");
            }
            else{
                printf("
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    虚拟机黑屏
    ngnix随笔三
    ngnix随笔二
    ngnix随笔一
    HTML(初级)笔记
    学习Java注解
    常用工具类与commons 类库
    SpringBoot缓存使用
    LeetCode:98.验证二叉搜索树
    剑指Offer:面试题07.重建二叉树
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14901484.html
Copyright © 2020-2023  润新知