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;
    } 
  • 相关阅读:
    oracle安装界面中文乱码解决
    Vmware esxi开启snmp服务
    sybase ase 重启
    zabbix通过snmp监控vmware vpshere5.5
    Linux下安装Sybase ASE 16
    DATAGUARD在做SWITCHOVER切换时遇到问题总结
    UVA 1564
    Drupal 7 模块开发 建立模块帮助信息(hook_help)
    HTML5实现图片文件异步上传
    RGCDQ(线段树+数论)
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14249195.html
Copyright © 2011-2022 走看看