1082. Read Number in Chinese (25)
2015-08-17 16:37
417 查看
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:
-123456789
Sample Output 1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
Sample Input 2:
100800
Sample Output 2:
yi Shi Wan ling ba Bai
用中文读数字;还带单位的(PS:这算按这种形式的读)
首先这里最多9个数字;
正数不读符号位
负数符号位读Fu
数字读对应的拼音全部小写,对应单位第一个大写,其他小写;
重点一,这种读法如果出现零要处理;1 0000 0000 为 yi Yi;108081 为yi Shi Wan ba Qian ling ba Shi yi;100000001为yi Yi ling yi
重点二,空格要处理;
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
8月17日 16:25 | 答案正确 | 25 | 1082 | C++ (g++ 4.7.2) | 1 | 356 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 248 | 9/9 |
1 | 答案正确 | 1 | 308 | 5/5 |
2 | 答案正确 | 1 | 356 | 4/4 |
3 | 答案正确 | 1 | 300 | 3/3 |
4 | 答案正确 | 1 | 304 | 4/4 |
#include<iostream> #include<string> using namespace std; string returnPinyin(char c) { switch (c) { case '0':return "ling\0"; case '1':return "yi\0"; case '2':return "er\0"; case '3':return "san\0"; case '4':return "si\0"; case '5':return "wu\0"; case '6':return "liu\0"; case '7':return "qi\0"; case '8':return "ba\0"; case '9':return "jiu\0"; } return "\0"; } string temindex(int len)/*后面有单位的加空格加单位,没有单位的比如len=1,不加空格不加单位*/ { switch (len) { case 5:return " Wan\0"; case 9:return " Yi\0"; } switch (len % 4) { case 0:return " Qian\0"; case 1:return "\0"; case 2:return " Shi\0"; case 3:return " Bai\0"; } return "\0"; } int main() { string str; string ans; int index; int count; bool zero; cin >> str; ans = "\0"; if (str[0] == '-') { ans = "Fu \0"; str.erase(0, 1); } index = 0; zero = false; while (!str.empty()) { count = 0; if (index == 0) { ans += returnPinyin(str[0]); ans += temindex(str.size()); str.erase(0, 1); index++; }/*第一个非符号数,用于处理格式,如果前有-,那么这里是- 数 单位;如果前面无-,那么这里数 单位*/ while (str.size()>0&&str[0] == '0' && str.size() % 4 != 1) { str.erase(0, 1); zero = true; count++; } if (zero&&str.size()>0 && str[0] != '0')/*循环出来有的一种情况10001,100000001需要直接零*/ { ans += " ling\0"; zero = false; } if (str.size()>1&&str.size() % 4 == 1 && str[0] == '0'&&count<3)/*循环出来的另一种情况,108181,不需要零,需要单位亿或者万 count用于处理1 0000 0000这个数字不需要单位万*/ { ans +=temindex(str.size()); } if (str.size() > 0 && str[0] != '0')/*不是第一个也不是零,直接 数 单位 */ { ans += " " + returnPinyin(str[0]); ans +=temindex(str.size()); } str.erase(0, 1); } cout << ans << endl; system("pause"); return 0; }
相关文章推荐
- Python matplotlib 画图相关
- 单词拆解&前缀树&树上DP LA 3942 Remember the Word
- IOS 如何实现画虚线
- 动画位于屏幕中央
- detection in video and image
- zabbix自动发现结合shell实现自动发现占用内存最大top10进程并监控其资源 推荐
- Arraylist和Vector区别
- Unicode(UTF-8, UTF-16)令人混淆的概念
- Url重定向
- 电话轰炸器
- SQL Server中如何获取当前年,月,日,时,分,秒
- Java 泛型
- 文本编辑器之editplus
- hdu 2094
- 群聊天记录,关于优化算法
- Linq打印
- zoj 3882 博弈 *
- Android Context的startService方法如何使用?
- POJ 2777-Count Color
- 04常量和变量