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 ...
随机推荐
- linux配置环境变量 - 认识
环境 ubuntu17.04 终端(就是黑框) 认识 环境变量:$PATH 在 ×××/bin 下的命令,可以不用到指定目录下, 比如:安装hbase后,hbase提供一些shell命令在habse ...
- 为什么选择Angular 2?
没有选择是痛苦的,有太多的选择却更加痛苦.而后者正是目前前端领域的真实写照.新的框架层出不穷:它难吗?它写得快吗?可维护性怎样?运行性能如何?社区如何?前景怎样?好就业吗?好招人吗?组建团队容易吗? ...
- Python Flask模块
模块是一个包含响应文本的文件,其中包含占用位变量表示的动态部分,其具体值只在请求的上下文中才知道.使用真实值替换变量,再返回最终得到的响应字符串,这一过程称为渲染.为了渲染模块,Flask使用一个名为 ...
- Spark大数据处理 之 RDD粗粒度转换的威力
在从WordCount看Spark大数据处理的核心机制(2)中我们看到Spark为了支持迭代和交互式数据挖掘,而明确提出了内存中可重用的数据集RDD.RDD的只读特性,再加上粗粒度转换操作形成的Lin ...
- linux 基本概念
Linux把物理内存分为了固定统一大小的块,称为page(页框),一般为4KB. Linux采用4KB页框大小作为标准的物理内存分配单元,内核用数据结构page描述一个页框的状态信息,其实页是进程的概 ...
- 使用Tensorflow object detection API——环境搭建与测试
[软件环境搭建] 操作系统:windows 10 64位 内存:8G CPU:I7-6700 Tensorflow: 1.4 Python:3.5 Anaconda3 (64-bit) 以上环境搭建请 ...
- shell控制流程
#!/bin/bash #存储为a.sh == ] then #参数正确,返回0 else #参数错误,返回1 fi #!/bin/bash #存储为b.sh echo $? $ . ./a.sh $ ...
- C语言的存储类别和动态内存分配
存储类别分三大类: 静态存储类别 自动存储类别 动态分配内存 变量.对象--->内存管理 内存考虑效率(时间更短.空间更小) 作用域 链接.---->空间 存储器 ----->时 ...
- day36 mysql 表的具体操作
一 库操作 1.创建数据库 1.1 语法 CREATE DATABASE 数据库名 charset utf8; 1.2 数据库命名规则 可以由字母.数字.下划线.@.#.$ 区分大小写 唯一性 ...
- day35 数据库的初步认识
一. 数据库的由来分类 1. 数据库的概念 百度定义: 数据库,简而言之可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据运行新增.截取.更新.删除等操作. 所谓“数据库”系 ...