1002.Read Number in Chinese (25)
来源:互联网 发布:php dynamodb 编辑:程序博客网 时间:2024/05/21 01:50
题目链接:http://www.nowcoder.com/pat/1/problem/4312
时间限制 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[N]!='\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;}
- 1002.Read Number in Chinese (25)
- Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese (25)
- pat 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese(25)
- PAT1082. 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)
- A1082. 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)
- CMD知识点
- hdu2602(01背包基础)
- html5 postMessage解决跨域、跨窗口消息传递
- artdialog弹出框
- HDU 5344(MZL's xor-(ai+aj)的异或和)
- 1002.Read Number in Chinese (25)
- 正常使用的ArcGIS10.0突然打不开(始终显示“正在初始化应用程序”),或者是Error提示: 无法打开或...
- Android Studio安装后Fetching android sdk component information超时的解决方案
- [笔记][Java7并发编程实战手册]3.5 在集合点的同步CyclicBarrier循环barrier
- Android studio 自动导入包 import(全部)
- Util:打开或关闭软键盘
- 性能调优攻略
- Reactor模式-反应器模式
- 深入理解Android卷III 第4章 深入理解WindowManagerSerivce (节选)