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;
    } 
  • 相关阅读:
    session之验证码
    session之cookie封装终极版本
    临床知识库-临床路径管理
    import org.quartz.Job; 不存在
    ASP.NET DataGrid 导出EXCEL 中文变乱码
    Cannot find module '@/views/monitor/online/index'
    配置包导入
    配置log4j 以便查看mybatis操作数据库的过程
    解决中文乱码问题
    ORA 环境变量
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14249195.html
Copyright © 2011-2022 走看看