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;
    }
    
    
  • 相关阅读:
    第十三周助教小结
    记事本
    第十二周助教小结
    与周老师会谈之后的感想
    第十一周总结
    第十周助教总结
    听周筠老师一席话,受益匪浅
    2020软件工程作业04
    2020软件工程作业02
    2020软件工程作业01
  • 原文地址:https://www.cnblogs.com/Qmelbourne/p/6060724.html
Copyright © 2011-2022 走看看