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. LSI阵列卡进行高效管理

    LSI公司(LSI Corporation)(NASDAQ:LSI)(中文:艾萨华)是一家总部位于加利福尼亚州米尔皮塔斯 (Milpitas) 的半导体和软件领先供应商,其主要产品包括:RAID控制器 ...

  2. DjVu、PDF中的隐藏文本

    作者:马健邮箱:stronghorse_mj@hotmail.com发布:2012.06.11 目录一.背景二.DjVu中的隐藏文本三.PDF中的隐藏文本 一.背景 目前对于扫描电子文档,网上比较流行 ...

  3. inline 内联函数

    1.目的: 引入内联函数的目的是为了解决程序中函数调用的效率问题. 函数的引入可以减少程序的目标代码,实现程序代码和数据的共享.但是,函数调用也会带来降低效率的问题,因为调用函数实际上将程序执行顺序转 ...

  4. java 学习第零篇JDK安装和记事本编辑JAVA(2)

    上面说了如何安装JDK那么这把就是来说怎么用记事本编写java 桌面上新建一个记事本 之后编写: public class a{    public static void main(String [ ...

  5. Luogu2114 [NOI2014]起床困难综合症 【位运算】

    题目分析: 按位处理即可 代码: #include<bits/stdc++.h> using namespace std; ; int n,m; int a[maxn],b[maxn]; ...

  6. AISing Programming Contest 2019C(DFS,BFS)

    #include<bits/stdc++.h>using namespace std;int n,m;long long a=0,b=0,ans=0;char s[407][407];in ...

  7. B - Pie (二分)

    My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...

  8. SQLAlchemy外键的使用

    orm可以将数据库存储的数据封装成对象,同时,如果封装的好的话,所有的数据库操作都可以封装到对象中.这样的代码在组织结构上会非常的清晰,并且相对与使用sql语句在sql注入方面会极具降低. SQLAl ...

  9. matplotlib类

    1.plt.subplot 在matplotlib下,一个Figure对象可以包含多个子图(Axes),可以使用subplot()快速绘制,其调用形式如下:subplot(numRows, numCo ...

  10. 再谈hive-1.0.0与hive-1.2.1到JDBC编程忽略细节问题

    不多说,直接上干货,这个问题一直迷惑已久,今天得到亲身醒悟. 所以,建议hadoop-2.6.0.tar.gz的用户与hive-1.0.0搭配使用.当然,也可以去用高版本去覆盖它. log4j:WAR ...