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

思路

逻辑题,有点恶心。。。
1.先输入一个数,将单个零和负数的情况先处理掉(后续将1亿的情况也单独处理掉)。
2.将该数的每一位数字用一个int数组的形式存放。
3.遍历该数组,根据该数组的每一位的位数和单个数字将对应的字符串插入到一个新的vector中,为0的位数除了是万位或者亿位以外都不用插入位数的字符串。
4.对于多余的零做处理,并输出每一位的数字和位数。 代码
#include<iostream>
#include<vector>
using namespace std;
vector<string> n={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
vector<string> digit={"","Shi","Bai","Qian","Wan","Shi","Bai","Qian","Yi"}; using namespace std;
int main()
{
vector<string> res;
vector<int> number;
int num,index;
cin >> num;
if(num == 0)
{
cout << "ling" << endl;
return 0;
}
else if( num < 0)
{
cout << "Fu ";
num = -num;
}
while(num != 0)
{
number.push_back(num % 10);
num /= 10;
} for(index = 0;index < number.size() && number[index] == 0;index++);
if(index == 8)
{
cout << n[number[index]] << " Yi";
return 0;
}
for(int i = index;i < number.size();i++)
{
if(i != 0 && (number[i] != 0 || i == 4 || i == 8))
res.push_back(digit[i]);
res.push_back(n[number[i]]);
}
for(int i = res.size() - 1;i >= 0;i--)
{
if(i != res.size() - 1)
cout << " ";
int zerocnt = 0;
while( i >= 0 && res[i] == "ling")
{
i--;
zerocnt++;
}
if(zerocnt > 0 && res[i] != "Wan")
{
cout << "ling ";
}
cout << res[i];
}
}

  

 

PAT1082:Read Number in Chinese的更多相关文章

  1. pat1082. Read Number in Chinese (25)

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

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

  3. PAT 1082 Read Number in Chinese[难]

    1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed to ...

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

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

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

  7. A1082. Read Number in Chinese

    Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...

  8. PTA (Advanced Level)1082.Read Number in Chinese

    Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...

  9. PAT甲级——A1082 Read Number in Chinese

    Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...

随机推荐

  1. Java进阶(九)正则表达式

    java正则表达式 序 由于项目中使用到了利用正则表达式进行表单的校验,回想一下正则表达式的内容,忘得也差不多了,俗话说:"温故而知新,可以为师矣".今天就简单的温故一下正则表达式 ...

  2. R12.2. Start and Stop Procedure

    R12.2. Start and Stop Procedure   Leave a comment Individual Components:  Application(Middle Tier) $ ...

  3. android Titlebar一行代码实现沉浸式效果

    github地址 一个简单易用的导航栏TitleBar,可以轻松实现IOS导航栏的各种效果  整个代码全部集中在TitleBar.java中,所有控件都动态生成,动态布局.不需要引用任何资源文件,拷贝 ...

  4. HADOOP中的CRC数据校验文件

    Hadoop系统为了保证数据的一致性,会对文件生成相应的校验文件(.crc文件),并在读写的时候进行校验,确保数据的准确性.在本地find -name *.crc -print 看 比如我们遇到的这个 ...

  5. android应用资源预编译,编译和打包全解析

    我们知道,在一个APK文件中,除了有代码文件之外,还有很多资源文件.这些资源文件是通过Android资源打包工具aapt(Android Asset Package Tool)打包到APK文件里面的. ...

  6. Linux下进程通信方式(简要概述)

    http://blog.sina.com.cn/s/blog_65c209580100u0ee.html (1)管道(Pipe):管道可用于具有亲缘关系进程间的通信,允许一个进程和另一个与它有共同祖先 ...

  7. 详解基于vue,vue-router, vuex以及addRoutes进行权限控制

    基于vuex, vue-router,vuex的权限控制教程,完整代码地址见https://github.com/linrunzheng/vue-permission-control 接下来让我们模拟 ...

  8. ExtJS中xtype 概览

    基本组件: xtype Class 描述 button Ext.Button 按钮 splitbutton Ext.SplitButton 带下拉菜单的按钮 cycle Ext.CycleButton ...

  9. javaScript(6)---流程控制语句

    学习要点: 1.语句的定义 2.if 语句 3.switch语句 4.do...while语句 5.while语句 6.for语句 7.for...in语句 8.break和continue语句 9. ...

  10. Unsupported major.minor version 51.0 错误解决方案

    jdk1.6工程中使用外部jar包中类出现:Unsupported major.minor version 51.0原因分析:出现上述错误是因为:外部jar包使用jdk1.7(jdk7)编译,而使用此 ...