zoukankan      html  css  js  c++  java
  • 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
    题意:求数字N中各位数字的和,并用英文输出
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<string.h>
    #include<cstdlib>
    using namespace std;
    const int maxn=10010;
    void change(int a[],int i){
            if(a[i]==0){
                cout<<"zero";
            }
            else if(a[i]==1){
                cout<<"one";
            }
            else if(a[i]==2){
                cout<<"two";
            }
            else if(a[i]==3){
                cout<<"three";
            }
            else if(a[i]==4){
                cout<<"four";
            }
            else if(a[i]==5){
                cout<<"five";
            }
            else if(a[i]==6){
                cout<<"six";
            }
            else if(a[i]==7){
                cout<<"seven";
            }
            else if(a[i]==8){
                cout<<"eight";
            }
            else if(a[i]==9){
                cout<<"nine";
            }
    }
    int main(){
        string N;
        cin>>N;
        long leng=N.length();
        long sum=0;
        for(int i=0;i<leng;i++){
            sum+=N[i]-'0';
        }
    //    cout<<sum<<endl;
        long s=sum;
        if(s==0){    //单独考虑为零的情况
            cout<<"zero"<<endl;
            return 0;
        }
        int a[maxn];
        int i=0;
        while(s!=0){
            a[i]=s%10;
            s/=10;
            i++;
        }
        for(int j=i-1;j>=0;j--){
            change(a,j);
            if(j>0){
                cout<<" ";
            }
            else{
                cout<<endl;
            }
        }
        
        return 0;
    } 
  • 相关阅读:
    GIT操作远程仓库
    GIT基本使用方式
    Docker网络及私有仓库配置
    Docker容器资源控制
    Docker基本使用方法
    [linux Tcmd] sh source
    hh
    推演论
    智能小车项目计划
    [CATARC_2017S] Week2
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14249195.html
Copyright © 2011-2022 走看看