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;
    } 
  • 相关阅读:
    Design pattern
    ArcSDE 快速入门
    struts2中s:select标签的使用
    CreateProcess error=87
    在DOS下添加用户
    加载SpringContext文件的方式
    svnkit获取svn相关信息
    Bat命令(管道与组合)
    JBOSS中使用RMI不能连接服务器的原因
    HTML中滚动条的样式设置
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14249195.html
Copyright © 2011-2022 走看看