#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. 文本比较命令:diff

      diff的三种模式,normal, context(-c), unified(-u)   一. 基本用法和例子   例1,比较2个文件的不同 root@hong-VirtualBox:~# dif ...

  2. java类的基本结构

    对象依赖于类存在. 分析过程先有对象后有类,开发过程中先有类后有对象. new是为新建对象开辟内存空间的运算符:以类为模板,开辟空间实例化一个对象,并返回该对象的一个引用. 成员变量 直接在类中定义 ...

  3. leetcode-551-Student Attendance Record I(判断是否出现连续几个相同字符)

    题目描述: You are given a string representing an attendance record for a student. The record only contai ...

  4. Mondrian Schema Workbench 概念及常用参数

    Schema Schema 定义了一个多维数据库.包含了一个逻辑模型,而这个逻辑模型的目的是为了书写 MDX 语言的查询语句.这个逻辑模型实际上提供了这几个概念: Cubes (立方体).维度( Di ...

  5. sql92和sql99

    sql1992sql分类 1.笛卡尔积 (表乘表) 2.等值连接 表的连接条件使用“=” 3.非等值连接 表的连接条件使用“>.>=. <.<=.!=.any等” 4.自连接 ...

  6. JAVA中 this关键字的用法

    this 在类中就是代表当前对象,可以通过 this 关键字完成当前对象的成员属性.成员方法和构造方法的调用. 那么何时用 this? 当在定义类中的方法时,如果需要调用该类对象,就可以用 this来 ...

  7. PIE SDK组件式开发综合运用示例

    1. 功能概述 关于PIE SDK的功能开发,在我们的博客上已经分门别类的进行了展示,点击PIESat博客就可以访问,为了初学者入门,本章节将对从PIE SDK组件式二次开发如何搭建界面.如何综合开发 ...

  8. netty总结

    eventLoopGroup中创建各个eventLoop处理线程,各个pipeLineHandler处理childEvent时是在自己的线程中, 全异步

  9. CentOS&.NET Core初试-1-CentOS的安装和网卡的配置

    系列目录 CentOS的安装和网卡的配置 安装.NET Core SDK和发布网站 Nginx的安装和配置 安装守护服务(Supervisor) 软件环境 系统版本:CentOS Linux rele ...

  10. Python爬虫抓取某音乐网站MP3(下载歌曲、存入Sqlite)

    最近右胳膊受伤,打了石膏在家休息.为了实现之前的想法,就用左手打字.写代码,查资料完成了这个资源小爬虫.网页爬虫, 最主要的是协议分析(必须要弄清楚自己的目的),另外就是要考虑对爬取的数据归类,存储. ...