1082 Read Number in Chinese (25分)
// 1082.cpp : 定义控制台应用程序的入口点。
// #include <iostream>
#include <string>
#include <vector>
using namespace std;
string str;
string s1[4] = { "Ge","Shi","Bai","Qian" };
string s2[10] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
vector<string> rs, t;
int main()
{
int n;
cin >> n;
if (n<0)
cout << "Fu ";
else if (n == 0) {
cout << "ling"; /*一个零特判*/
return 0;
}
str = to_string(abs(n));
int len = str.size();
for (int i = 0; i < len; i++) {
rs.push_back(s2[str[i] - '0']);
int pos = len - i - 1;
if (pos % 4 && str[i] != '0') /* 0十->0*/
rs.push_back(s1[pos % 4]);
if (pos == 4)
rs.push_back("Wan"); /*到万位加万,亿位加亿*/
if (pos == 8)
rs.push_back("Yi");
}
for (int i = 0; i < rs.size(); i++) {
t.push_back(rs[i]);
if (i != 0 && rs[i] == "ling"&&rs[i - 1] == "ling") /*删除连续的零为一个零*/
t.pop_back();
}
t.push_back("Wan");
for (int i = 0; i < t.size()-1; i++) {
if (t[i] == "ling" && t[i + 1] == "Wan" )/*删除单个不需要的零如有1000->yi qian ling->yi qian*/
continue;
if (i != 0)
cout << " ";
cout << t[i];
}
return 0;
}
https://pintia.cn/problem-sets/994805342720868352/problems/994805385053978624
1082 Read Number in Chinese (25分)的更多相关文章
- 【PAT甲级】1082 Read Number in Chinese (25 分)
题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...
- 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 ...
- 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 ...
- 1082. Read Number in Chinese (25)-字符串处理
题意就是给出9位以内的数字,按照汉子的读法读出来. 读法请看下方的几个例子: 5 0505 0505 伍亿零伍佰零伍万零伍佰零伍 5 5050 5050 伍亿伍仟零伍拾万伍仟零伍拾 (原本我以为这个 ...
- PAT (Advanced Level) 1082. Read Number in Chinese (25)
模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- pat1082. Read Number in Chinese (25)
1082. Read Number in Chinese (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- maven一直加载2.0.0.M7 的 config server 失败
之前学习的时候使用F版的SpringBoot管理项目依赖一直好好的,今天不知idea为何抽疯,一直加载失败,各种重启,清除,没用 只能像之前学习注册consul 时将F版的SpringBoot 改为G ...
- Hadoop3.1.1架构体系——设计原理阐述与Client源码图文详解 : 总览
一.设计原理 1.Hadoop架构: 流水线(PipeLine) 2.Hadoop架构: HDFS中数据块的状态及其切换过程,GS与BGS 3.Hadoop架构: 关于Recovery (Lease ...
- Linux常用命令英文全称与中文解释 (pwd、su、df、du等)
https://blog.csdn.net/qq_40334837/article/details/83819735 Linux常用命令英文全称与中文解释 apt: Advanced Packagin ...
- Go第三方库之tail
Tail Demo // tail.TailFile()函数开启goroutine去读取文件,通过channel格式的t.lines传递内容. t, err := tail.TailFile(&quo ...
- 【音乐欣赏】《99》 - MOB CHOIR
曲名:99 作者:MOB CHOIR [00:00.000] 作曲 : 佐々木淳一 [00:00.150] 作词 : 佐々木淳一 [00:00.450] [00:02.370]If everyone ...
- 如何安装和使用Maven
今天我们来学习一下如何安装Maven,把步骤分享给大家,希望能对大家有帮助! 我的博客地址:https://www.cnblogs.com/themysteryofhackers/p/11996550 ...
- 04hive查询
详细文档查看:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Select 一. 基本查询(SELECT …FROM) ...
- Python(五) 迭代器(Iterable/Iterator/iter())
原文的链接:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143178254 ...
- FYF的煎饼果子
利用等差数列公式就行了,可以考虑特判一下m >= n($ m, n \neq 1 $),这时一定输出“AIYAMAYA”. #include <iostream> using nam ...
- 「JSOI2015」salesman
「JSOI2015」salesman 传送门 显然我们为了使收益最大化就直接从子树中选大的就好了. 到达次数的限制就是限制了可以选的子树的数量,因为每次回溯上来都会减一次到达次数. 多种方案的判断就是 ...