HDU 1727 Hastiness

来源:互联网 发布:久其软件打不开 编辑:程序博客网 时间:2024/05/25 01:36

题目链接

题目意思

给你一个不大于四位数的数字,输出它的英文写法。

解题思路

就是一道暴力题。不过很容易出错,要考虑的情况比较多。所以做题的时候得认真一点。

代码部分

#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <map>using namespace std;map<int, string> M;map<int, string> M1;map<int, string> M2;void init(){    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[0] = "zero";    M1[1] = "ten";    M1[2] = "twenty";    M1[3] = "thirty";    M1[4] = "forty";    M1[5] = "fifty";    M1[6] = "sixty";    M1[7] = "seventy";    M1[8] = "eighty";    M1[9] = "ninety";    M2[0] = "ten";    M2[1] = "eleven";    M2[2] = "twelve";    M2[3] = "thirteen";    M2[4] = "fourteen";    M2[5] = "fifteen";    M2[6] = "sixteen";    M2[7] = "seventeen";    M2[8] = "eighteen";    M2[9] = "nineteen";}int main(){    int t;    while(~scanf("%d",&t))    {        init();        if(t<10)///个位数            cout<<M[t]<<endl;        else if(t>=10&&t<20)///十位数            cout<<M2[t-10]<<endl;        else if(t>=20&&t<100)        {            if(t%10==0)                cout<<M1[t/10]<<endl;            else                cout<<M1[t/10]<<"-"<<M[t%10]<<endl;        }        else if(t>=100&&t<1000)///百位数        {            if(t%100==0)                cout<<M[t/100]<<" hundred"<<endl;            else            {                if(t%100<10)                    cout<<M[t/100]<<" hundred and "<<M[t%100]<<endl;                else if(t%100>=10&&t%100<20)                    cout<<M[t/100]<<" hundred and "<<M2[t%100-10]<<endl;                else                {                    if((t%100)%10==0)                        cout<<M[t/100]<<" hundred and "<<M1[t%100/10]<<endl;                    else                        cout<<M[t/100]<<" hundred and "<<M1[t%100/10]<<"-"<<M[t%100%10]<<endl;                }            }        }        else///千位数        {            if(t%1000==0)                cout<<M[t/1000]<<" thousand"<<endl;            else            {                if(t%1000<10)                    cout<<M[t/1000]<<" thousand and "<<M[t%1000]<<endl;                else if(t%1000>=10&&t%1000<20)                    cout<<M[t/1000]<<" thousand and "<<M2[t%1000-10]<<endl;                else if(t%1000>=20&&t%1000<100)                {                    if((t%1000)%10==0)                        cout<<M[t/1000]<<" thousand and "<<M1[(t%1000)/10]<<endl;                    else                        cout<<M[t/1000]<<" thousand and "<<M1[t%1000/10]<<"-"<<M[t%1000%10]<<endl;                }                else                {                    if((t%1000)%100==0)                        cout<<M[t/1000]<<" thousand and "<<M[t%1000/100]<<" hundred"<<endl;                    else                    {                        if((t%1000)%100<10)                            cout<<M[t/1000]<<" thousand and "<<M[(t%1000)/100]<<" hundred and "<<M[t%1000%100]<<endl;                        else if((t%1000)%100>=10&&(t%1000)%100<20)                             cout<<M[t/1000]<<" thousand and "<<M[(t%1000)/100]<<" hundred and "<<M2[t%1000%100-10]<<endl;                        else                        {                            if(((t%1000)%100)%10==0)                                cout<<M[t/1000]<<" thousand and "<<M[(t%1000)/100]<<" hundred and "<<M1[((t%1000)%100)/10]<<endl;                            else                                cout<<M[t/1000]<<" thousand and "<<M[(t%1000)/100]<<" hundred and "<<M1[((t%1000)%100)/10]<<"-"<<M[((t%1000)%100)%10]<<endl;                        }                    }                }            }        }    }    return 0;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 好动症的孩子该怎么办 18个月宝宝腹泻怎么办 8个月小孩发烧怎么办 八个月大宝宝发烧怎么办 8个月宝宝拉稀水怎么办 八个月宝宝38度怎么办 8个月的宝宝发烧怎么办 八个月大的宝宝拉肚子怎么办 9孩子上课坐不住怎么办 3岁宝宝太皮怎么办 4岁的宝宝多动症怎么办 小孩好动注意力不集中怎么办 乐扣加热变形了怎么办 3岁宝宝咳嗽厉害怎么办 六个月婴儿呕奶怎么办 刚出生婴儿呕奶怎么办 宝宝拉颗粒便便怎么办 奶水不够宝宝又不吃奶粉怎么办 一岁突然不吃饭怎么办 母乳不够吃宝宝不吃奶粉怎么办 八个月不吃辅食怎么办 孩子长得太快怎么办 反复发烧到39度怎么办 儿童发烧到39度怎么办 7岁儿童发烧40度怎么办 7岁反复发烧39度怎么办 宝宝烧到39.5度怎么办 3岁儿童发烧39度怎么办 孩子发高烧怎么办39度5 3岁宝宝不吃水果怎么办 2岁宝宝不吃水果怎么办 4岁宝宝不吃水果怎么办 过早竖抱婴儿了怎么办 3个月宝宝认生怎么办 10天婴儿不拉屎怎么办 3个月宝宝不吃奶粉怎么办 婴儿吃青菜吃多怎么办 2月宝宝消化不好怎么办 吃母乳的宝宝便秘怎么办 婴儿拉肚子怎么办大便绿色的 10个月宝宝睡眠不好怎么办