题目描述

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. pandas中series求交集

    在进行数据探索的时候会遇到求交集的情况,比如说:优惠卷预测的时候,有多张表,表1有用户id,表2也有用户id,但是不能确定表1的用户有多少出现在表2当中. un_id1,un_id2 为两个 Seri ...

  2. nodejs http ejs

    // ejs-demo.jsvar http = require('http'); var ejs = require('ejs'); var url = require('url'); // 搭建 ...

  3. 常见的arp欺骗

    三.常见ARP欺骗形式 1.假冒ARP reply包(单播) XXX,I have IP YYY and my MAC is ZZZ! 2.假冒ARP reply包(广播) Hello everyon ...

  4. [NOIP2005] 过河【Dp,思维题,缩点】

    Online Judge:Luogu P1052 Label:Dp,思维题,缩点,数学 题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子 ...

  5. vue better-scroll 下拉上拉,加载刷新

    _initScroll(){             this.$nextTick(() => {                 if (!this.scroll) {             ...

  6. node---处理get请求

    const http=require('http') const querystring=require('querystring') const server = http.createServer ...

  7. python2与python3编码

    #coding:utf8#一#1.在python2中,默认以ASCII编码chcp 936import sysprint sys.getdefaultencoding()# ascii#str:byt ...

  8. 尚学python课程---12、python语言介绍

    尚学python课程---12.python语言介绍 一.总结 一句话总结: 1.操作简单:简便计算:允许通过单个“import”语句后跟一个函数调用来完成复杂的计算.虽慢 2.库丰富:比如人工智能和 ...

  9. System.DateTime.cs

    ylbtech-System.DateTime.cs 1. 程序集 mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5 ...

  10. private定义的static字段子其他类能通过"类名.字段名"调用吗?

    不能!