1002.Read Number in Chinese (25)
2015-08-22 17:46
309 查看
题目链接:http://www.nowcoder.com/pat/1/problem/4312
时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)
时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)
题目描述
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”.输入描述:
Each input file contains one test case, which gives an integer with no more than 9 digits.输出描述:
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.输入例子:
-123456789输出例子:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu代码 C++:
#include <iostream> int main(){ char *num = new char[11]; char d[10][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; int i, N, a[8], ling=0; bool first = true; scanf("%s",num); if(*num=='-'){ printf("Fu "); num = num+1; } for(N=0;num !='\0';N++); if(N==9){ printf("%s Yi",d[*num-'0']); first = false; } else if(N==1){ printf("%s",d[*num-'0']); return 0; } for(i=0;i<8&&N>0;i++) a[i] = num[--N]-'0'; for(i--;i>=0;i--){ if(a[i]==0) ling ++; else{ if(ling){ printf("%sling",first?"":" "); first = false; ling = 0; } printf("%s%s",first?"":" ",d[a[i]]); first = false; switch(i){ case 1: case 5: printf(" Shi"); break; case 2: case 6: printf(" Bai"); break; case 3: case 7: printf(" Qian");break; } } if(i==4&&ling<4){ printf(" Wan"); ling = 0; } } return 0; }
相关文章推荐
- [笔记][Java7并发编程实战手册]3.5 在集合点的同步CyclicBarrier循环barrier
- hdu2602(01背包基础)
- Programming internal SRAM over SWD
- HDU3790最短路径问题
- HYSBZ-2243(树链剖分)
- wpf Datagrid 的全选
- delphi发送html带附件邮件
- 1655 文本计算器
- html5 postMessage解决跨域、跨窗口消息传递
- oracle学习笔记一:用户管理(1)简单的命令
- CMD知识点
- make条件判断ifeq,ifneq,ifdef,ifndef
- 自定义视图
- pat(B) 1013. 数素数
- bzoj1050:旅行comf
- Hibernate数据库连接池
- IT该忍者神龟Instant client required
- JS解析json数据(如何将json字符串转化为数组)
- android 使用OkHttp上传多张图片
- asdfasdfasdfasdf