PAT甲级——A1082 Read Number in Chinese
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
.
Input Specification:
Each input file contains one test case, which gives an integer with no more than 9 digits.
Output Specification:
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.
Sample Input 1:
-123456789
Sample Output 1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
Sample Input 2:
100800
Sample Output 2:
yi Shi Wan ling ba Bai
吐槽一波,这就不能算是算法题,纯属是字符串硬处理
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string num[] = { "ling","yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" };
string c[] = { "Ge","Shi", "Bai", "Qian", "Yi", "Wan" };
int J[] = { , , , , , , , , };
vector<string> res;
int main() {
int n;
cin >> n;
if (n == ) {
cout << "ling";
return ;
}
if (n < ) {
cout << "Fu ";
n = -n;
}
int part[];
part[] = n / ;
part[] = (n % ) / ;
part[] = n % ;
bool zero = false; //是否在非零数字前输出合适的ling
int printCnt = ; //用于维护单词前没有空格,之后输入的单词都在前面加一个空格。
for (int i = ; i < ; i++) {
int temp = part[i]; //三个部分,每部分内部的命名规则都一样,都是X千X百X十X
for (int j = ; j >= ; j--) {
int curPos = - i * + j; //当前数字的位置
if (curPos >= ) continue; //最多九位数
int cur = (temp / J[j]) % ;//取出当前数字
if (cur != ) {
if (zero) {
printCnt++ == ? cout << "ling" : cout << " ling";
zero = false;
}
if (j == )
printCnt++ == ? cout << num[cur] : cout << ' ' << num[cur]; //在个位,直接输出
else
printCnt++ == ? cout << num[cur] << ' ' << c[j] : cout << ' ' << num[cur] << ' ' << c[j]; //在其他位,还要输出十百千
}
else {
if (!zero&&j != && n / J[curPos] >= ) zero = true; //注意100020这样的情况
}
}
if (i != && part[i] > ) cout << ' ' << c[i + ]; //处理完每部分之后,最后输出单位,Yi/Wan
}
return ;
}
PAT甲级——A1082 Read Number in Chinese的更多相关文章
- 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 ...
- 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 ...
- A1082. Read Number in Chinese
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...
- PAT 甲级 1117 Eddington Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805354762715136 British astronomer Edd ...
- PAT 甲级 1024 Palindromic Number
1024. Palindromic Number (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)
1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backw ...
- PAT甲级——A1117 Eddington Number【25】
British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, h ...
- PAT甲级——A1024 Palindromic Number
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
随机推荐
- 收藏的链接-English
What is the adverb for deposit? https://www.wordhippo.com/what-is/the-adverb-for/deposit.html
- Codeforces 479【C】div3
题目链接:http://codeforces.com/problemset/problem/977/C 题意:给你n个数字,输出任意一个数字,这个数字刚好大于等于,序列里面k个数字. 题解:排个序,第 ...
- Spark运行基本流程
- Java 基础 - CLASSPATH 到底是什么
关于JAVA项目中CLASSPATH路径详解 https://www.cnblogs.com/hibou/p/8324276.html java项目中的classpath到底是什么 https://s ...
- Altera FPGA– Bit Slip
通过在接收端加延时,在延时间隙插入'0'或'1',以使最终接收和期望数据一致. BitSlip操作要注意几点: 1,BitSlip操作在rx_bitslip的上升沿即开始: 2,BitSlip操作开始 ...
- Windows 开启win32 控制台
{ AllocConsole(); FILE *Journal = NULL; freopen_s(&Journal, "CONOUT$", &qu ...
- day10 nfs服务,nginx负载均衡,定时任务
==================nginx 负载均衡==================== 实现nginx负载均衡的效果,并运用nfs服务共享目录,使所有nginx服务拥有共同的http目录 n ...
- Kubernetes的包管理工具Helm的安装和使用
1.源码安装 [root@master ~]# wget https://storage.googleapis.com/kubernetes-helm/helm-v2.14.0-linux-amd64 ...
- 20.multi_case06
# coding:utf-8 import asyncio # 通过create_task()方法 async def a(t): print('-->', t) await asyncio.s ...
- C 遍历目录及其子目录
遍历某一目录,获取该目录下所有文件路径的数组 #include <iostream> #include <dirent.h> #include <vector> v ...