pat1082. Read Number in Chinese (25)
1082. Read Number in Chinese (25)
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
数的读法转换,比较灵活。具体见代码注释。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
string dight[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
string id[]{"","Wan","Yi"};
string num[]{"","Shi","Bai","Qian"};
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
string s;
cin>>s;
reverse(s.begin(),s.end());
int i=s.length()-,j;
queue<string> q;
if(s[i]=='-'){
i--;
q.push("Fu");
}
if(s[i]==''){//特殊情况
q.push("ling");
i--;
}
for(;i>=;i--){
j=i;
if(i>=&&s[i]==''){
while(i>=&&s[i]==''){
i--;
}
i++;//保证i一定>=0
if(i/==j/){//0在同一区间
if(i%!=){//连续的0在区间中段
q.push("ling");
}
}
else{//多个0跨越区间
q.push(id[j/]);//只可能跨越万和个的区间
if(i!=){//最后一个0不是个位
q.push("ling");
}
}
}
else{
q.push(dight[s[i]-'']);
if(i%!=){//不是个位的情况
q.push(num[i%]);
}
}
if(i%==&&i>){//到了区间末尾
q.push(id[i/]);
}
}
cout<<q.front();
q.pop();
while(!q.empty()){
cout<<" "<<q.front();
q.pop();
}
cout<<endl;
return ;
}
pat1082. Read Number in Chinese (25)的更多相关文章
- PAT1082:Read Number in Chinese
1082. Read Number in Chinese (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- A1082 Read Number in Chinese (25)(25 分)
A1082 Read Number in Chinese (25)(25 分) Given an integer with no more than 9 digits, you are suppose ...
- A1082 Read Number in Chinese (25 分)
1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed t ...
- 1082. Read Number in Chinese (25)
题目如下: Given an integer with no more than 9 digits, you are supposed to read it in the traditional Ch ...
- 1082. Read Number in Chinese (25)-字符串处理
题意就是给出9位以内的数字,按照汉子的读法读出来. 读法请看下方的几个例子: 5 0505 0505 伍亿零伍佰零伍万零伍佰零伍 5 5050 5050 伍亿伍仟零伍拾万伍仟零伍拾 (原本我以为这个 ...
- PAT (Advanced Level) 1082. Read Number in Chinese (25)
模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 【PAT甲级】1082 Read Number in Chinese (25 分)
题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...
- 1082 Read Number in Chinese (25分)
// 1082.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <string> #include <vecto ...
- 1082 Read Number in Chinese (25 分)
1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed to ...
随机推荐
- vue配置vue-router
首先理清一下几个路由的基础概念: 1)route是一条路由,也就是映射,即A按钮→A内容,以数组形式存储 2)toutes:[]是一组路由,里面包含了若干条route,即route[{A按钮→A内容} ...
- layui下select下拉框不显示或没有效果
Layui会对select.checkbox.radio等原始元素隐藏,从而进行美化修饰处理.但这需要依赖于form组件,所以你必须加载 form,并且执行一个实例.值得注意的是:导航的Hover效果 ...
- 如何在Linux上使用x2go设置远程桌面
Until ACS supports Spice, if ever,you're better off with "on-VM" softare such RDP for Wind ...
- Python3中开发目录的引用
Python3中开发目录的引用 import os,sys BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ...
- day05.3-Linux进程管理
1. 通过top指令可查看系统当前进程信息. 2. 通过free指令可查看系统内核信息.其中 free -m:以M为单位查看内核: free -h:以G为单位查 ...
- 2018沈阳网赛F--上下界网络流
建图: 首先加一个源点s和汇点t,分别连接在二分图的左边和右边,每条弧的上下界为[L, R],二分图左边和右边之间连弧上下界为[0,1],其实就相当于连弧为1. 然后问题就转换为:有源汇最大流. 继续 ...
- [BZOJ1799][Ahoi2009]self 同类分布(数位dp)
题目描述 给出两个数 a,ba,b ,求出 [a,b][a,b] 中各位数字之和能整除原数的数的个数. 输入输出格式 输入格式: 一行,两个整数 aa 和 bb 输出格式: 一个整数,表示答案 输入输 ...
- 老男孩Day7作业:选课系统
1.作业需求:角色:学校.学员.课程.讲师 1. 创建北京.上海 2 所学校 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开 3. 课程包 ...
- webpack 的使用教程
webpack 的使用教程 今天接触webpack,就着官网上的教程一步一步的玩,把自己的理解总结以便和大家交流 webpack的主要特点 1. 可以把js,css,image,甚至文本当成模块来处理 ...
- Hbase0.98.0完全分布式搭建---【使用外部zookeeper】
Hbase是一个分布式的实时数据库,他可以基于hadoop的hdfs,S3等分布式存储系统.而且使用zookeeper来通信(查询元数据和获取数据所在位置等功能) 本文的Hbase使用的是hadoop ...