PAT甲级——【牛客练习题1002】
题目描述
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".
输入描述:
Each input file contains one test case, which gives an integer with no more than 9 digits.
输出描述:
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.
输入例子:
-123456789
输出例子:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
#include <iostream>
#include <vector>
#include <string> using namespace std; int main()
{
vector<string> level = { "Fu","Shi","Bai","Qian" };
vector<string> Wei = { "","Wan","Yi" };
vector<string> numbers = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
vector<string> res;
string Num;
cin >> Num;
if(Num[] == '-')//如果是负数
{
res.push_back(level[]);
Num.erase(, );
}
int n = Num.length();
if (n == )//如果只有一位,则直接输出即可并结束
{
cout << numbers[Num[] - ''] << endl;
return ;
}
int f = ;
for (int i = ; i < n; ++i)
{
int a = Num[i] - '';//取出数字
int p = (n - i - ) % ;//判断是否是4位间隔
if (a > )
{
if (f)//中间有零存在
{
res.push_back(numbers[]);
f = ;
}
res.push_back(numbers[a]);//输入数字
if (p > )//不是各位
res.push_back(level[p]);//输入位
}
else if (p != )//当中间有0且不是0不是在个位上
f = ;
if (p == && res[res.size() - ] != "Yi")//是4位间隔且中间不是全为0,例如100000004,就不用输出wan
res.push_back(Wei[(n - i) / ]);
}
for (int i = ; i < res.size() - ; ++i)
cout << res[i] << " ";
cout << res[res.size() - ] << endl;//最后一位不用输出空格
return ;
}
PAT甲级——【牛客练习题1002】的更多相关文章
- PAT甲级——【牛客练习题100】
题目描述 Given N rational numbers in the form "numerator/denominator", you are supposed to cal ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级1056Mice and Rice
目录 题目介绍 题解 解题思路 代码 参考链接 题目介绍 题目链接 https://pintia.cn/problem-sets/994805342720868352/problems/9948054 ...
- PAT甲级训练刷题代码记录
刷题链接:https://www.patest.cn/contests/pat-a-practise 1001 #include <iostream> #include <stdio ...
- 牛客网_Go语言相关练习_判断&选择题(6)
本文共34道题目 一.判断题 此题考查编码规范. 反射最常见的使用场景是做对象的序列化(serialization,有时候也叫Marshal & Unmarshal). 例如:Go语言标准库的 ...
- PAT乙级(Basic Level)练习题-NowCoder数列总结
题目描述 NowCoder最近在研究一个数列: F(0) = 7 F(1) = 11 F(n) = F(n-1) + F(n-2) (n≥2) 他称之为NowCoder数列.请你帮忙确认一下数列中第n ...
- PAT甲级1131. Subway Map
PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...
- PAT甲级1107. Social Clusters
PAT甲级1107. Social Clusters 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...
- PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名
题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...
随机推荐
- NuGet包介绍
Antlr 各种语言的语法识别器.解析器.编译和翻译器 Microsoft.AspNet.Web.Optimization 绑定优化CSS和JavaScript文件,也就是App_Start下的Bun ...
- Linux安全审计-基础篇
安全审计这块我能想到的有两种方案可以解决,一种是在Linux中配置实现,一种是使用Python开发堡垒机实现,我先实现了第一种比较简单的:后面会开发堡垒机: 一.首先我们需要在/etc/profi ...
- C# async await 举个栗子
首先,async 和 await 代表异步执行和等待. async是一个标记,告诉编译器,我可能是一个异步方法. await 代表等待,告诉编译器,这里等我返回结果. 下面,我们简单说一下. 一 , ...
- sikuli+eclipse对于安卓app自动化测试的应用(第一次写博客,有些语言还不太专业,望海涵)
Sikuli是什么? 下面是来自于官网的介绍:Sikuli is a visual technology to automate and test graphical user interfaces ...
- 基于vue,通过父组件触发子组件的请求,等请求完毕以后,显示子组件,同时隐藏父组件
正常情况下,子组件应该尽量减少业务逻辑,而应该将业务逻辑放到父组件里面,从而减少耦合,但是当 我们不得不用到这种情况时,可以采用下面的思路 解决方案 尽量将请求单独作为一个函数(不要将请求放到show ...
- js面试总结2
原型和原型链: 题目,知识点,解答: 1.如何准确地判断一个变量是数组类型 2.写一个原型链继承的例子 3.描述new一个对象的过程 4.zepto(或其他框架)源码中如何使用原型链. 知识点 构造函 ...
- Android Scroller简单用法 --View滚动
转:http://ipjmc.iteye.com/blog/1615828 Android里Scroller类是为了实现View平滑滚动的一个Helper类.通常在自定义的View时使用,在View中 ...
- mysql重点,表查询操作和多表查询
表单查询 1. 完整的查询语句语法 select distinct(* or 字段名 or 四则运算 )from 表名 where 条件 group by 条件 having 条件 order by ...
- pycharm for mac安装
http://www.xue51.com/mac/5604.html
- vue之样式问题
在样式开发过程中,有两个问题比较突出: 全局污染 —— CSS 文件中的选择器是全局生效的,不同文件中的同名选择器,根据 build 后生成文件中的先后顺序,后面的样式会将前面的覆盖: 选择器复杂 — ...