【PAT甲级】1082 Read Number in Chinese (25 分)
题意:
输入一个九位整数,输出它的汉字读法(用拼音表示)。
trick:
字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int num[];
string united[]={"","yi","er","san","si","wu","liu","qi","ba","jiu"};
string unit[]={"","","Shi","Bai","Qian","Wan","Shi","Bai","Qian"};
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int x;
cin>>x;
if(x<){
cout<<"Fu ";
x=-x;
}
else if(x==){
cout<<"ling";
return ;
}
int tamp=;
for(int i=;i<=;++i)
tamp*=;
for(int i=;i;--i){
num[i]=x/tamp;
x%=tamp;
tamp/=;
}
int space=;
if(num[])
cout<<united[num[]]<<" Yi",space=;
int pos=;
for(int i=;i;--i)
if(num[i]){
pos=i;
break;
}
int ling=;
if(num[]&&pos<)
ling=;
for(int i=pos;i;--i){
if(num[i]){
if(space)
cout<<" ",space=;
if(ling)
cout<<"ling",ling=,space=;
if(space)
cout<<" ",space=;
cout<<united[num[i]],space=;
if(i!=&&i!=){
if(space)
cout<<" ",space=;
cout<<unit[i],space=;
}
}
else if(!ling&&i!=)
ling=;
if(i==){
if(space)
cout<<" ",space=;
cout<<"Wan",space=;
}
}
return ;
}
【PAT甲级】1082 Read Number in Chinese (25 分)的更多相关文章
- 1082 Read Number in Chinese (25分)
// 1082.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <string> #include <vecto ...
- 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 ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT甲级:1089 Insert or Merge (25分)
PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...
- PAT 甲级 1145 Hashing - Average Search Time (25 分)(读不懂题,也没听说过平方探测法解决哈希冲突。。。感觉题目也有点问题)
1145 Hashing - Average Search Time (25 分) The task of this problem is simple: insert a sequence of ...
- PAT 甲级 1066 Root of AVL Tree (25 分)(快速掌握平衡二叉树的旋转,内含代码和注解)***
1066 Root of AVL Tree (25 分) An AVL tree is a self-balancing binary search tree. In an AVL tree, t ...
- PAT 甲级 1055 The World's Richest (25 分)(简单题,要用printf和scanf,否则超时,string 的输入输出要注意)
1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires base ...
- PAT 甲级 1047 Student List for Course (25 分)(cout超时,string scanf printf注意点,字符串哈希反哈希)
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cou ...
- PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*
1039 Course List for Student (25 分) Zhejiang University has 40000 students and provides 2500 cours ...
随机推荐
- oracle dataguard配置
1.archivelog设置:(存档模式) 2.standy controlfile 设置: alter database create standby controlfile as '/data/o ...
- c数据结构 绪论
四种逻辑结构:1:集合结构 结构中的数据元素除了同属于同一个集合的关系外,无任何其他关系2:线性结构 结构中的数据元素之间存在着一对一的线性关系3:树形结构 结构中的数据元素之间存在着一对多的层次关系 ...
- js面向对象的程序设计 --- 上篇(理解对象)
前言 ECMAScript中没有类的概念,因此它们的对象与基于类的语言中的对象有所不同. ECMA-262把对象定义为:"无序的集合属性,其属性可以包含基本值,对象或者函数".正因 ...
- 数据库too many connections 解决方法
问题:网站后台突然报错了,显示“too many connections........”这是咋回事? 解决: 先罗列几个有用的操作: ① mysql -u root -p 回车输入密码进入mysq ...
- ES6新的数据类型 generato,在AJAX中的应用
1.next()方法会执行generator的代码,然后,每次遇到yield x;就返回一个对象{value: x, done: true/false},然后“暂停”.返回的value就是yield的 ...
- js函数防抖和函数节流
参考链接:https://juejin.im/post/5b651dc15188251aa30c8669 参考链接:https://www.jb51.net/article/158818.htm 在我 ...
- HTML学习(12)列表
HTML包括有序列表ol(ordered list).无序列表ul(unordered list).自定义列表dl(difinition list) 有序列表: <ol start=" ...
- C语言数据结构——第三章 栈和队列
三.栈和队列 栈和队列是两种重要的线性结构.从数据结构的角度来看,栈和队列也是线性表,它的特殊性在于栈和队列的基本操作是线性表操作的子集,它们的操作相对于线性表来说是受到限制的,因此,可以称其为限定性 ...
- Linux06——安装JDK、Tomcat、Eclipse
一.安装JDK(具体解压命令在Linux02中) ①将JDK解压到opt目录下(opt就是文件夹) ②配置环境变量 vim /etc/profile JAVA_HOME=/opt/jdk1.8.0 ...
- C++11 Lambda函数
Lambda函数 C++11新增了lambda函数,其基本格式如下 [捕捉列表] (参数) mutable -> 返回值类型 {函数体} 说明 []是lambda的引出符,捕捉列表能够捕捉上下文 ...