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 ...
随机推荐
- 重启nginx:端口被占用问题
1.重启nginx出现端口占用问题: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 2.解决方法: 第 ...
- HTML学习(7)格式化标签
对文本格式进行编辑的标签.常用: <b>加粗文本</b> <strong>加重语气</strong> 与<b>效果一样,<stro ...
- mysql5.7导出数据提示--secure-file-priv选项问题的解决方法
mysql可使用 into outfile 参数把表中数据导出到csv,例如可用以下命令把user表的数据导出到user.csv select * from user into outfile '/t ...
- 牛客1080D tokitsukaze and Event (双向最短路)
题目链接:https://ac.nowcoder.com/acm/contest/1080/D 首先建两个图,一个是权值为a的图,一个是权值为b的图. 从s起点以spfa算法跑权值为ai的最短路到t点 ...
- 560. 和为K的子数组
Q: A: 1.暴力找所有可能的子数组,n^2个子数组,最长长度n,则n ^3. 2.n^2解法 从1~n-1各起点开始,一直找到结尾,n^2 class Solution { public: int ...
- const在C与C++中的区别
在C中,const不是常量,只能说是一个不能改变的变量(注意是变量),C编译器不能把const看成看成一个编译期间的常量,因为他在内存中有分配,C编译器不知道他在编译期间的值.所以不能作为数组定义时的 ...
- vue 实现上一周、下一周切换功能
效果图: html 显示部分: js 显示部分: preNextBtn(val){ let _this = this; this.tableList = []; //数据重置为空 _this.show ...
- python之nosetest
nose介绍 nose下载 nose使用 -s 能够打印用例中的print信息 ➜ func_tests git:(master) ✗ nosetests -v test_app.py:TestApp ...
- 安装Tengine版本的nginx
安装tengine版nginx #!/bin/bash yum install epel-release -y yum install gcc unzip gcc-c++ git wget bind- ...
- blog主题——黑夜
blog主题,存储一下 /* Author: Io_oTI*/ /*Public*/ * { margin: 0; padding: 0; box-sizing: border-box; trans ...