HDU 1727 Hastiness

Problem Description

How many problems did you AC? 
When you read this problem, don’t hasty and careless, this is also simple, haha, I didn’t cheat you. 
The game over soon, WisKey starts using English begin countdown. He not only have no gene in math, but also bad in English. Fortunately, He met you who have gift in programming. So please help him to translate.

Input

Give you an integer T, output T in English, and note that all of words are lower case. (0<=T<=9999)

Output

One answer One line. 
Details see sample.

Sample Input

2034 
1234 
123 
24 
0

Sample Output

two thousand and thirty-four 
one thousand and two hundred and thirty-four 
one hundred and twenty-three 
twenty-four 
zero

C++

#include<iostream>
#include<map>
#include<string>
#include<cstring>
using namespace std;
int main()
{
    int a,b,c,d;
    int n[5];
    map<int,string>m;
    map<int,string>s;
    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";
    m[10]="ten";
    m[11]="eleven";
    m[12]="twelve";
    m[13]="thirteen";
    m[14]="fourteen";
    m[15]="fifteen";
    m[16]="sixteen";
    m[17]="seventeen";
    m[18]="eighteen";
    m[19]="nineteen";
    s[2]="twenty";
    s[3]="thirty";
    s[4]="forty";
    s[5]="fifty";
    s[6]="sixty";
    s[7]="seventy";
    s[8]="eighty";
    s[9]="ninety";
    while(cin>>b)
    {
        a=0;
        c=b;
        if(b<20)
            cout<<m[b]<<endl;
        else
        {
            if(b>=1000)
            {
                cout<<m[b/1000]<<" thousand";
                b=b%1000;a=1;
            }
            if(b>=100)
            {
                if(a==1)
                {
                    cout<<" and ";
                    a=0;
                }
                cout<<m[b/100]<<" hundred";
                b=b%100;a=1;
            }
            if(b>=20)
            {
                if(a==1)
                {
                    cout<<" and ";
                    a=0;
                }
                cout<<s[b/10];
                if(b%10!=0)
                    cout<<"-"<<m[b%10];
            }
            else if(b!=0)
            {
                if(a==1)
                {
                    cout<<" and ";
                    a=0;
                }
                cout<<m[b];
            }
            cout<<endl;
        }
    }
    return 0;
}





全部评论

相关推荐

贺兰星辰:不要漏个人信息,除了简历模板不太好以外你这个个人简介是不是太夸大了...
点赞 评论 收藏
分享
昨天 00:11
已编辑
广东工业大学 算法工程师
避雷深圳&nbsp;&nbsp;yidao,试用期&nbsp;6&nbsp;个月。好嘛,试用期还没结束,就直接告诉你尽快找下一家吧,我谢谢您嘞
牛客75408465号:笑死,直属领导和 hr 口径都没统一,各自说了一些离谱的被裁理由,你们能不能认真一点呀,哈哈哈哈哈😅😅😅
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务