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;
    }
    
    
  • 相关阅读:
    水平居中
    flex布局
    get新技能:上传了 flv 或 MP4 文件到服务器,可访问总是出现 “无法找到该页”的 404 错误
    小程序3.8
    小程序3.7
    Vue 中select option默认选中的处理方法
    HTML5 data属性
    静态html返回
    node中可读流、可写流
    node.js fs、http使用
  • 原文地址:https://www.cnblogs.com/Qmelbourne/p/6060724.html
Copyright © 2011-2022 走看看