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 ...
随机推荐
- winFrom程序更新自动安装
我就以一个计算字符长度的程序为例子吧界面如下 代码如下 [C#] 纯文本查看 复制代码 ? 01 02 03 04 private void button1_Click(object sender, ...
- Unity中Awake的执行时间点
https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html 根据官方文档,Awake的实际执行点,应该是对应mono脚本所在物体 ...
- (转)深入研究 蒋金楠(Artech)老师的 MiniMvc(迷你 MVC),看看 MVC 内部到底是如何运行的
前言 跟我一起顺藤摸瓜剖析 Artech 老师的 MiniMVC 是如何运行的,了解它,我们就大体了解 ASP.NET MVC 是如何运行的了.既然是“顺藤摸瓜”,那我们就按照 ASP.NET 的执行 ...
- web安全-密码安全
web安全-密码安全 1.密码的作用 2.储存 3.传输 4.替代方案 5.生物特征密码 (指纹 人脸) 6.密码单向变换彩虹表 组合 密码变换次数越多越安全 加密成本几乎不变(生成密码速度慢一点) ...
- java方法里面生成js弹出框
核心代码:方法参数要有response response.setContextType("text/html;charset=UTF-8"); PrintWrite out = r ...
- 搜索【洛谷P2845】 [USACO15DEC]Switching on the Lights 开关灯
P2845 [USACO15DEC]Switching on the Lights 开关灯 题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一 ...
- 【NOIP 2015】斗地主
题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的 A 到 K 加上大小王的共 54 张牌来进行的扑克牌游戏.在斗地主中,牌的大小关 系根据牌的数码表示如下: 3 ...
- Julia体验 语言特性 元编程,宏
上接语言基础,就release-1.1来看,个人感觉这门语言和自己心中的理想国相距较远.这门语言因为受众不仅仅是程序员有很多让人迷惑的设计,但是奇怪的是它的语法等表象设计虽然暗示这不是专门为程序员准备 ...
- liunx一次安装多个软件包
https://blog.csdn.net/finded/article/details/44955953 编写shell脚本程序 一次安装多个软件,主要用于一些软件依赖环境配置. 1.shell脚本 ...
- 使用nexus 搭建本地 maven 服务器
1.下载安装nexus oos https://www.sonatype.com/download-oss-sonatype ,选择2.x 版本. 2. 配置maven <server> ...