#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm> using namespace std; const char* d2cn[] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
const char* t2cn[] = {"Ge", "Shi", "Bai", "Qian"}; void num2cn(int num, vector<string>& out) {
vector<string> tmp;
int i = ;
int last = ;
while (num) {
int cur = num % ;
if (cur != || last != ) {
if (i != && cur != ) {
tmp.push_back(string(t2cn[i]));
}
tmp.push_back(string(d2cn[cur]));
}
last = cur;
num /= ;
i++;
}
reverse(tmp.begin(), tmp.end());
out.insert(out.end(), tmp.begin(), tmp.end());
} int main() {
vector<string> out;
int N;
scanf("%d", &N);
int num = N;
if (num < ) {
out.push_back("Fu");
num = -num;
} int ds[] = {};
int i = ;
int yi = num / ;
num = num % ;
int wan = num / ;
int ge = num % ; if (yi != ) {
out.push_back(d2cn[yi]);
out.push_back("Yi");
}
if (wan != ) {
if (wan < && yi != ) {
out.push_back("ling");
}
num2cn(wan, out);
out.push_back("Wan");
} if (ge != ) {
if (ge < && (yi | wan)) {
out.push_back("ling");
}
num2cn(ge, out);
}
if (out.size() == ) {
printf("ling");
} else {
printf("%s", out[].c_str());
int len = out.size();
for (int i=; i<len; i++) {
printf(" %s", out[i].c_str());
}
}
printf("\n");
return ;
}

坚持

PAT 1082. Read Number in Chinese的更多相关文章

  1. 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 ...

  2. 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 ...

  3. PAT (Advanced Level) 1082. Read Number in Chinese (25)

    模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  4. 【PAT甲级】1082 Read Number in Chinese (25 分)

    题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...

  5. 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 ...

  6. PTA (Advanced Level)1082.Read Number in Chinese

    Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...

  7. 1082 Read Number in Chinese

    Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...

  8. 1082. Read Number in Chinese (25)-字符串处理

    题意就是给出9位以内的数字,按照汉子的读法读出来. 读法请看下方的几个例子: 5 0505 0505 伍亿零伍佰零伍万零伍佰零伍 5 5050 5050 伍亿伍仟零伍拾万伍仟零伍拾  (原本我以为这个 ...

  9. 1082 Read Number in Chinese (25分)

    // 1082.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <string> #include <vecto ...

随机推荐

  1. NFS共享服务

    一.网络文件系统共享服务 NFS( Network File System,网络文件系统 )是一种基于TCP/IP传输的网络文件系统协议,最初由SUN公司开发,通过使用NFS协议,客户机可以像访问本地 ...

  2. Python 中的 10 个常见安全漏洞,以及如何避免(下)

    简评:编写安全代码很困难,当你学习一个编程语言.模块或框架时,你会学习其使用方法. 在考虑安全性时,你需要考虑如何避免被滥用,Python 也不例外,即使在标准库中,也存在用于编写应用的不良实践.然而 ...

  3. P3879 [TJOI2010]阅读理解 题解

    P3879 [TJOI2010]阅读理解 题解 题目描述 英语老师留了N篇阅读理解作业,但是每篇英文短文都有很多生词需要查字典,为了节约时间,现在要做个统计,算一算某些生词都在哪几篇短文中出现过. 输 ...

  4. 条目二十二《切勿修改set或multiset的键》

    条目二十二<切勿修改set或multiset的键> 所有的标准关联容器一样,set和multiset按照一定的顺序来存放自己的元素,而这些容器的正确行为也是建立在其元素保持有序的基础之上的 ...

  5. python全栈开发_day11_作用域,函数嵌套和闭包

    一:作用域 1)什么是作用域 作用域是规定一个变量可以作用的范围,运行和销毁的范围 2)作用域的分类 1.内置作用域built_in:随着解释器的运行而产生,解释器运行的终止而销毁. 2.全局作用域g ...

  6. js toFixed 方法重写,兼容负数

    Number.prototype.toFixed = function (s) { var that = this, changenum, index; if (this < 0) { that ...

  7. module.exports,exports,export和export default,import与require区别与联系

    还在为module.exports.exports.export和export default,import和require区别与联系发愁吗,这一篇基本就够了! 一.首先搞清楚一个基本问题: modu ...

  8. Fiddler模拟发送post请求

    fiddler在进行接口测试时,会模拟post请求,发送不同的请求参数,返回不同的结果,今天我们就来分享一下,怎么用Fiddler工具模拟post请求: 打开Fiddler工具,在右侧点击“compo ...

  9. Request笔记

    1 Request 的简介和运行环境 1.HttpServletRequest 概述 我们在创建 Servlet 时会覆盖 service()方法,或 doGet()/doPost(),这些方法都有两 ...

  10. Unity Github 项目收集

    http://gad.qq.com/article/detail/24048 重磅推荐: Github 热门 Unity Assets 查询:http://unitylist.com/browse 最 ...