1082. Read Number in Chinese
来源:互联网 发布:lol总是网络断开连接 编辑:程序博客网 时间:2024/05/16 21:58
1082. Read Number in Chinese (25)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is read as "Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu". Note: zero ("ling") must be handled correctly according to the Chinese tradition. For example, 100800 is "yi Shi Wan ling ba Bai".
Input Specification:
Each input file contains one test case, which gives an integer with no more than 9 digits.
Output Specification:
For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.
Sample Input 1:-123456789Sample Output 1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiuSample Input 2:
100800Sample Output 2:
yi Shi Wan ling ba Bai
因为位数有限而且不多,就直接处理好了,h万和l(1-999)有类似的地方,注意空格的输出和ling的输出。
要对0这个输入特殊处理一下。
#include<iostream>#include<string>#include<cmath>using namespace std;string num[10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};string unit[5]={"","Shi","Bai","Qian","Wan"};int main(){int n;cin>>n;if(n==0){cout<<"ling";return 0;}if(n<0)cout<<"Fu ";n=abs(n);if(n/100000000)cout<<num[n/100000000]<<" Yi";bool f=n/100000000;n=n%100000000;if(n&&f)cout<<" ";int h=n/10000;bool f0=!f;int op=1000;int cnt=3;while(h){if(h/op){cout<<num[h/op];f0=false;if(cnt)cout<<" "<<unit[cnt];if(h%op)cout<<" ";}else if(!f0){cout<<"ling ";f0=true;}h=h%op;op=op/10;cnt--;}if(n/10000)cout<<" Wan";int l=n%10000;if(l&&n/10000)cout<<" ";f0=!(f||n/10000);op=1000;cnt=3;while(l){if(l/op){cout<<num[l/op];f0=false;if(cnt)cout<<" "<<unit[cnt];if(l%op)cout<<" ";}else if(!f0){cout<<"ling ";f0=true;}l=l%op;op=op/10;cnt--;}}
0 0
- 1082.Read Number in Chinese
- 1082. Read Number in Chinese
- 1082. Read Number in Chinese
- PAT 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese
- pat 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese(25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- 【PAT】1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25)
- Md5加密算法
- iOS开发第三方分享 QQ分享
- 当需要使窗口除了点击标题栏以外还可以移动的解决方案 WM_NCHITTEST
- 如何安装和使用纯文本编辑器 vi/vim
- Weiss-(DSAA - in C,2.13)求素数的3个方法
- 1082. Read Number in Chinese
- 数据结构之栈
- 第7周项目4 -列队数组
- 编译配置
- stl学习(三)crope的用法
- noip2013 转圈游戏 快速幂
- poj 3164 Command Network【最小树形图】
- 有1000桶酒,其中1桶有毒。而一旦吃了,毒性会在1周后发作。 现在我们用小老鼠做实验,要在1周内找出那桶毒酒,问最少需要多少老鼠。 (老鼠的使用量越少越好,注意,毒性1周后才会发作,而且一周后必须出
- css布局-搜索框制作