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 (<= 10100).

    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最大是10得100次方,用整形存储肯定不够,用字符串存储后就过了




    #include <iostream>
    #include <string>
    #include <map>
    
    using namespace std;
    
    map<char,string> m;
    int result[100005];
    
    int main()
    {
        m[0]="zero";
        m[1]="one";
        m[2]="two";
        m[3]="three";
        m[4]="four";
        m[5]="five";
        m[6]="six";
        m[7]="seven";
        m[8]="eight";
        m[9]="nine";
        string n;
        long int sum=0;
        cin>>n;
        int b,i=0;
        while(n[i]!=''){
            b=n[i]-48;
            sum=sum+b;
            i++;
        }
        int x,countnum=0;
        while(sum){
            x=sum%10;
            result[countnum]=x;
            countnum++;
            sum=sum/10;
        }
        cout<<m[result[countnum-1]];
        for(int i=countnum-2;i>=0;i--){
            cout<<" "<<m[result[i]];
        }
    
        return 0;
    }
    
    
  • 相关阅读:
    Java之static理解
    linux安装vsftpd
    JS获取当前时间戳的三个方法
    git常用操作
    npm更新包
    springboot的mvn与gradle启动方式
    mac nginx compile
    [文摘]那些一心想要离开 BAT 的人,后来怎么样了?
    excel 常用法
    chrome 快捷键
  • 原文地址:https://www.cnblogs.com/Qmelbourne/p/6060724.html
Copyright © 2011-2022 走看看