1082. Read Number in Chinese (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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)的更多相关文章

  1. PAT1082:Read Number in Chinese

    1082. Read Number in Chinese (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 1082. Read Number in Chinese (25)-字符串处理

    题意就是给出9位以内的数字,按照汉子的读法读出来. 读法请看下方的几个例子: 5 0505 0505 伍亿零伍佰零伍万零伍佰零伍 5 5050 5050 伍亿伍仟零伍拾万伍仟零伍拾  (原本我以为这个 ...

  6. PAT (Advanced Level) 1082. Read Number in Chinese (25)

    模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  7. 【PAT甲级】1082 Read Number in Chinese (25 分)

    题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...

  8. 1082 Read Number in Chinese (25分)

    // 1082.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <string> #include <vecto ...

  9. 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 ...

随机推荐

  1. volatile关键字小结

    Java 提供了一种稍弱的同步机制,即 volatile 变量,用来确保将变量的更新操作通知到其他线程.可以将 volatile 看做一个轻量级的锁,但是又与锁有些不同: 1. 对于多线程,不是一种互 ...

  2. day06.1-磁盘管理

    1. 添加磁盘 打开虚拟机,依次点击"编辑虚拟机设置" |—> "添加" |—> "硬盘" |—> "选择硬盘类 ...

  3. 循环队列(Joseplus Problem)

    #include <iostream> #include <stdio.h> using namespace std; ]; ; void Enqueue(int x) { ) ...

  4. Percona Toolkit安装、使用

    percona-toolkit是一组高级命令行工具的集合,用来执行各种通过手工执行非常复杂和麻烦的mysql和系统任务,这些任务包括: l  检查master和slave数据的一致性 l  有效地对记 ...

  5. 【转】使用母版页时内容页如何使用css和javascript

    源地址:https://www.cnblogs.com/accumulater/p/6767138.html

  6. Python学习过程(二)

    条件判断和循环 条件判断 age = 20 if age >= 18: print 'your age is',age print 'adult' elif age >=6 : print ...

  7. P4213 【模板】杜教筛(Sum) min_25筛

    \(\color{#0066ff}{ 题目描述 }\) 给定一个正整数\(N(N\le2^{31}-1)\) 求 \(ans_1=\sum_{i=1}^n\varphi(i)\) \(ans_2=\s ...

  8. MySQL数据查询结果导出生成文件

    select url from news where url like "%美女%"  into outfile  "/导出的文件路径" : 在这里有个坑,对于 ...

  9. 洛谷 P1028 数的计算

    嗯... 首先这道题想到的就是递推.... 但是递推失败 (不知道自己是怎么想的 然后又想打一个暴力,但是数的最高位太难存储了,所以又放弃了(并且好像这个暴力大约500就会炸... 然后看了题解,才发 ...

  10. vue项目中使用了vw适配方案,引入第三方ui框架mint-ui时,适配问题解决

    问题分析: 一般第三方ui框架用的都是不同的适配方式,如果我们使用了vw适配,那么在使用mint-ui框架时,就会发现px单位会被转换成vw,从而导致样式变小的问题,如图 解决方案 网上看到了很多种解 ...