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;}
阅读全文
0 0
- HDU 1727 Hastiness
- HDU 1727-Hastiness
- HDU 1727 Hastiness(模拟)
- HDU 1727 Hastiness
- HDU 1727 Hastiness
- HDU 1727:Hastiness
- HDU 1727 Hastiness(模拟)
- hdu-1727-Hastiness(字符处理)
- Hastiness(1727)
- hdoj-1727Hastiness
- hdoj 1727 Hastiness
- HDU 1727 Hastiness纯粹的英文单词拼写(就当背英文数字的单词啦)
- Hastiness-hd1727-map
- hdu
- hdu
- HDU
- hdu ()
- hdu
- Cadence初学笔记
- hive分区表
- Qt之等待提示框(QTimer)
- POJO类一对多关系配置 有顺序存取
- div,table
- HDU 1727 Hastiness
- 大数据学习笔记(四)-ZooKeeper
- 6.idea安装以及配置
- Leetcode 题解系列(九)
- 任意输入一个三位数,判断该书是否是水仙花数。若是输出“yes”,否则输出“no”。
- HDOJ 1720 A+B Coming
- MIME类型是什么?包含哪些类型?
- BFC浅析
- 深入理解Java的接口和抽象类