PAT 1082. Read Number in Chinese
#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的更多相关文章
- 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 ...
- 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 ...
- PAT (Advanced Level) 1082. Read Number in Chinese (25)
模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 【PAT甲级】1082 Read Number in Chinese (25 分)
题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...
- 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 ...
- 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 ...
- 1082 Read Number in Chinese
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...
- 1082. Read Number in Chinese (25)-字符串处理
题意就是给出9位以内的数字,按照汉子的读法读出来. 读法请看下方的几个例子: 5 0505 0505 伍亿零伍佰零伍万零伍佰零伍 5 5050 5050 伍亿伍仟零伍拾万伍仟零伍拾 (原本我以为这个 ...
- 1082 Read Number in Chinese (25分)
// 1082.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <string> #include <vecto ...
随机推荐
- windows使用putty向远程服务器传送文件
一.问题产生 对于远程服务器,我习惯把文件写好后直接上传到服务器,也有很多方法可以做到,我现在比较习惯使用putty自带的pscp直接去传. 二.解决办法 1.首先在本地下载的putty文件下看是否有 ...
- javascipt中数组的常见操作
1.与lua不同,即使数组中间有null或者undefined,仍然能求出正确的长度 2.length 改变.length也会改变数组的大小 3. indexOf arr.indexOf(a)会返回第 ...
- Python yield 的基本概念和用法
之前解析MQTT协议时,需要做一个等分字节流的操作,其中用到了yield关键字,如下: def get_var_length(hstring): m = 1 v = 0 for element in ...
- iOS开发苹果内购的介绍与实现
1.iOS开发苹果内购的介绍 1.1 介绍 苹果规定,凡是虚拟的物品(例如:QQ音乐的乐币)进行交易时,都必须走苹果的内购通道,苹果要收取大约30%的抽成,所以不允许接入第三方的支付方式(微信.支付宝 ...
- EXTJS文档地址
文档地址:http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.form.field.Field-event-change
- Java 继承学习
Java 继承 继承实现: 在Java中,如果实现继承的,需要使用Java关键字——extends : 被继承的类叫做超类,继承超类的类叫子类.(一个子类亦可以是另一个类的超类) class 子类 e ...
- Android中判断service是否在运行
/** * 判断服务是否开启 * * @return */ public static boolean isServiceRunning(Context context, String Service ...
- 利用C#结合net use命令破解域帐号密码
背景 我的职业是程序猿,而所在的工作单位因各种原因,对上网帐号有严格控制,近期竟然把我们的上网帐号全部停用,作为程序猿,不能上网,就如同鱼儿没有水,煮饭没有米,必须想办法解决此问题.公司的局域网环境是 ...
- python+selenium的搭建过程
搭建步骤 1.第一步没啥好说的,肯定是先安装python 下载地址:http://download.csdn.net/detail/intel80586/4297269 全部默认安装即可. 安装完毕后 ...
- sencha touch SortableList 的使用
转: sencha touch 2.3 多了一个 SortableList plugin, 可实现 list item 的拖动交换 Ext.require('Ext.plugin.SortableL ...