题目描述

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. 整理及优化CSS代码的7个原则

    作为网页设计师(前端工程师),你可能还记得曾经的那个网页大小建议:一个网页(包括HTML.CSS.Javacript.Flash和图片)尽量不要超过30KB的大小,随着互联网的日益庞大,网络带宽也在飞 ...

  2. Apache Spark 2.2.0 中文文档 - Spark SQL, DataFrames and Datasets

    Spark SQL, DataFrames and Datasets Guide Overview SQL Datasets and DataFrames 开始入门 起始点: SparkSession ...

  3. The linux command 之 扩展

    echo * " * "字符意味着匹配文件名中的任意字符,shell会在执行echo命令之前把*扩展成其他内容. 一.路径扩展(pathname Expansion) 通过使用通配 ...

  4. python open函数关于w+ r+ 读写操作的理解(转)

    r 只能读 (带r的文件必须先存在)r+ 可读可写 不会创建不存在的文件.如果直接写文件,则从顶部开始写,覆盖之前此位置的内容,如果先读后写,则会在文件最后追加内容.w+ 可读可写 如果文件存在 则覆 ...

  5. mysql连接卡死,很多线程sleep状态,导致CPU中mysqld占用率极高

    关闭所有 .................................. .连接: ##把全部的MySQL连接kill掉for i in $(mysql -uroot -p123456 -Bse ...

  6. 剑指Offer-14:输入一个链表,输出该链表中倒数第k个结点。

    题目描述: 输入一个链表,输出该链表中倒数第k个结点.例如有一个链表有六个节点1,2,3,4,5,6.则它的倒数第二个节点为5 节点定义如下: public class ListNode { int ...

  7. 2816: [ZJOI2012]网络

    传送们 把一个点拆成c个即可 浪费时间的水题... //Achen #include<algorithm> #include<iostream> #include<cst ...

  8. day22_1-课前上节复习+os模块

    # ********************day22_1-课前上节复习+os模块 *******************# ********************day22_1-课前上节复习+os ...

  9. Spring MVC(十四)--SpringMVC验证表单

    在Spring MVC中提供了验证器可以进行服务端校验,所有的验证都必须先注册校验器,不过校验器也是Spring MVC自动加载的,在使用Spring MVC校验器之前首先要下载相关的jar包,下面是 ...

  10. [kuangbin带你飞]专题一 简单搜索 - A - 棋盘问题

    #include<iostream> #include<cstdio> #include<string> #include<vector> #inclu ...