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. R-- Apply族函数

    APPLY族函数: apply(x,a,f) 对矩阵或数据框的某一维度作用函数fx为矩阵或数据框:a为1代表行,a为2代表列:f为作用函数. lapply(x,f) 对x的每一个元组作用函数f,结果以 ...

  2. 开源,免费和跨平台 - MVP ComCamp 2015 KEYNOTE

    2015年1月31日,作为KEYNOTE演讲嘉宾,我和来自全国各地的开发人员分享了作为一名MVP的一些体会. Keynote – Open Source, Free Tools and Cross P ...

  3. 队列链式存储 - 设计与实现 - API函数

    队列相关基础内容参我的博文:队列顺序存储 - 设计与实现 - API函数 队列也是一种特殊的线性表:可以用线性表链式存储来模拟队列的链式存储. 主要代码: // linkqueue.h // 队列链式 ...

  4. LeetCode之“动态规划”:Unique Binary Search Trees && Unique Binary Search Trees II

    1. Unique Binary Search Trees 题目链接 题目要求: Given n, how many structurally unique BST's (binary search ...

  5. Systemc在VC++2010安装方法及如何在VC++2010运行Noxim模拟器

    Systemc在VC++2010的安装方法可以参考文档"Systemc with Microsoft Visual Studio 2008.pdf".本文档可以在"htt ...

  6. Android Camera开发系列(上)——Camera的基本调用与实现拍照功能以及获取拍照图片加载大图片

    Android Camera开发系列(上)--Camera的基本调用与实现拍照功能以及获取拍照图片加载大图片 最近也是在搞个破相机,兼容性那叫一个不忍直视啊,于是自己翻阅了一些基本的资料,自己实现了一 ...

  7. Android开发技巧——自定义控件之组合控件

    Android开发技巧--自定义控件之组合控件 我准备在接下来一段时间,写一系列有关Android自定义控件的博客,包括如何进行各种自定义,并分享一下我所知道的其中的技巧,注意点等. 还是那句老话,尽 ...

  8. 【Qt编程】3D迷宫游戏

    说起迷宫想必大家都很熟悉,个人感觉迷宫对人的方向感是很大的考验,至少我的方向感是不好的,尤其是在三维空间中.由于这段时间帮导师做项目用到了三维作图,便心血来潮想做个三维迷宫玩玩.要想画出三维的迷宫游戏 ...

  9. SharePoint 2013 新建网站集图解(绝对菜鸟篇)

    前言:接触SharePoint的人可能是越来越多,但是很多人一接触就很迷茫,在技术群里问如何新建网站集,这样一篇图解,帮助新手学习在搭建好SharePoint环境之后,如何创建一个网站集,做一个基本的 ...

  10. 视频博文结合的教程:用nodejs实现简单的爬虫

    教学视频地址: https://v.qq.com/x/page/b0643tut4ze.html 前言   本喵最近工作中需要使用node,并也想晋升为全栈工程师,所以开始了node学习之旅,在学习过 ...