题目描述

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

  1. PAT甲级——【牛客练习题100】

    题目描述 Given N rational numbers in the form "numerator/denominator", you are supposed to cal ...

  2. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  3. PAT甲级1056Mice and Rice

    目录 题目介绍 题解 解题思路 代码 参考链接 题目介绍 题目链接 https://pintia.cn/problem-sets/994805342720868352/problems/9948054 ...

  4. PAT甲级训练刷题代码记录

    刷题链接:https://www.patest.cn/contests/pat-a-practise 1001 #include <iostream> #include <stdio ...

  5. 牛客网_Go语言相关练习_判断&选择题(6)

    本文共34道题目 一.判断题 此题考查编码规范. 反射最常见的使用场景是做对象的序列化(serialization,有时候也叫Marshal & Unmarshal). 例如:Go语言标准库的 ...

  6. PAT乙级(Basic Level)练习题-NowCoder数列总结

    题目描述 NowCoder最近在研究一个数列: F(0) = 7 F(1) = 11 F(n) = F(n-1) + F(n-2) (n≥2) 他称之为NowCoder数列.请你帮忙确认一下数列中第n ...

  7. PAT甲级1131. Subway Map

    PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任 ...

  8. PAT甲级1107. Social Clusters

    PAT甲级1107. Social Clusters 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...

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

随机推荐

  1. 2018-12-22-WPF-在绑定表达式添加计算

    title author date CreateTime categories WPF 在绑定表达式添加计算 lindexi 2018-12-22 16:12:56 +0800 2018-12-22 ...

  2. .Net Core JWT Bearer 的认证

    关于JWT原理在这不多说,主要由三部分组成:Header.Payload.Signature,有兴趣自己上网了解. 1.首先创建.Net Core 一个Api项目 2.添加 JWT 配置 2.1 修改 ...

  3. 解决VS2012新建MVC4等项目时,收到此模板加载程序集“NuGet.VisualStudio.Interop…”的错误

    1.错误如图所示: 2.不管是VS2012,还是2013如果开始没安装Nuget包都或报这个错,因为VS2012就已经全面切换到使用NuGet这个第三方开源工具来管理项目包和引用模块了,使用VS201 ...

  4. c# 使用Expression 生成sql

    使用Expression 生成sql  update语句的时候遇到了个问题 ,Expression<Action<T>>  la   这个委托里面老获取不到 引用类型的值,甚至 ...

  5. 数据库MySQL--联合查询

    应用场景:当要查询的结果来自多个表,且多个表没有直接的连接关系,但查询的信息一致时 语法: 查询语句1 union(all) 查询语句2 union(all) ..... 注:多条查询语句的查询列数要 ...

  6. 数据库MySQL--连接查询

    例子文件1:https://files.cnblogs.com/files/Vera-y/myemployees.zip 例子文件2:https://files-cdn.cnblogs.com/fil ...

  7. Android开发 retrofit入门讲解 (RxJava模式)

    前言 retrofit除了正常使用以外,还支持RxJava的模式来使用,此篇博客讲解如何使用RxJava模式下的retrofit 依赖 implementation 'com.squareup.ret ...

  8. SQL Server 2008 install

    双击sql server 2008的.exe安装文件,进入[SQL Server 安装中心]. 2 点击界面左侧的[安装],然后点击右侧的[全新SQL Server 独立安装或向现有安装添加功能],进 ...

  9. prometheus配置详情

    https://prometheus.io/docs/prometheus/latest/configuration/configuration/ 下面监控宿主机和容器的内存,CPU,磁盘等状态 gr ...

  10. springmvc 拦截器不拦截jsp,只拦截控制器的访问

    spring是鼓励把jsp放到WEB-INF文件夹中,然后通过控制器进行访问