• 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;
    } 
  • 相关阅读:
    Compiling and Installing Yate on Windows
    Windows系统下的TCP参数优化
    TCP参数参数调优
    在浏览器测试JavaScript的方法
    万物智能互联时代
    shopify主题Grid模板修改
    Invalid argument supplied for foreach() in wpinclude/scriptloader.php如何解决
    shopify主题模板startup修改
    shopify主题Pacific模板配置修改
    qperf 简要总结 延迟与带宽信息
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14249195.html
Copyright © 2020-2023  润新知