#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. 4,临界区 之 synchronized

    前提背景:多个并发线程共享同一个资源时,为防止这些共享资源可能出现的错误或数据不一致问题,提出了临界区的概念 临界区: 指一个用以访问共享资源的代码块,这个代码块在同一时间内只能允许一个线程访问 实现 ...

  2. UIResponder笔记

    UIResponder是什么 可以响应UIEvent的类,是UIApplication, UIView及UIViewController的父类.它的父类是NSObject 管理第一响应者. 是否是第一 ...

  3. C# - Common Tool

    Json 涉及命名空间 using System.IO; using System.Net; using System.Runtime.Serialization.Json; using Newton ...

  4. Objective-C语法基础:面向对象编程特点的总结

    1.类的声明与实现 Objective-C类的声明要写在@interface 与 @end之间,实现要写在@implementation 与 @end之间 2.类的-方法和+方法 类的-方法即类的实例 ...

  5. P1444 [USACO1.3]虫洞wormhole

    luogu P1444 [USACO1.3]虫洞wormhole 首先感谢ghj的讲解 题目描述 农夫约翰爱好在周末进行高能物理实验的结果却适得其反,导致N个虫洞在农场上(2<=N<=12 ...

  6. string.Format("rspauth={0}",

    public string rspauth(string Username, string Realm, string Password, string Nonce, string Cnonce,   ...

  7. JavaWeb学习笔记(二十二)—— 过滤器filter

    一.什么是过滤器 过滤器filter是JavaWeb三大组件之一,它与Servlet很相似!不过过滤器是用来拦截请求的,而不是处理请求的.WEB开发人员通过Filter技术,对web服务器管理的所有w ...

  8. Android调用 .Net Core WebApi 返回数据,用FastJSON解析一直报错。

    问题描述:.Net Core WebApi中用Newtonsoft.Json 把datatable转成json字符串,如:JsonConvert.SerializeObject(table,Forma ...

  9. Oracle递归查询(start with…connect by prior)

    查询基本结构: select … from table_name       start with 条件1       connect by 条件2 1.建测试用表 create table test ...

  10. android面试注意点

    Java 基础知识 面向对象的基本思想 Object类相关:Object类的几个关键函数.String涉及到的常量池概念,序列化 & 反序列化. 重要关键字:final.static. 内部类 ...