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

题意:

输入一个九位整数,输出它的汉字读法(用拼音表示)。

trick:

字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误。

代码:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int num[17];
string united[17]={"","yi","er","san","si","wu","liu","qi","ba","jiu"};
string unit[17]={"","","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<0){
cout<<"Fu ";
x=-x;
}
else if(x==0){
cout<<"ling";
return 0;
}
int tamp=1;
for(int i=1;i<=8;++i)
tamp*=10;
for(int i=9;i;--i){
num[i]=x/tamp;
x%=tamp;
tamp/=10;
}
int space=0;
if(num[9])
cout<<united[num[9]]<<" Yi",space=1;
int pos=0;
for(int i=8;i;--i){
if(num[i]){
pos=i;
break;
}
}
int ling=0;
if(num[9]&&pos<8)
ling=1;
for(int i=pos;i;--i){
if(num[i]){
if(space)
cout<<" ",space=0;
if(ling)
cout<<"ling",ling=0,space=1;
if(space)
cout<<" ",space=0;
cout<<united[num[i]],space=1;
if(i!=5&&i!=1){
if(space)
cout<<" ",space=0;
cout<<unit[i],space=1;
}
}
else{
if(!ling&&i!=5)
ling=1;
}
if(i==5){
if(space)
cout<<" ",space=0;
cout<<"Wan",space=1;
}
}
return 0;
}

原文地址:https://www.cnblogs.com/ldudxy/p/11865893.html

时间: 2024-11-05 20:25:42

【PAT甲级】1082 Read Number in Chinese (25 分)的相关文章

PAT 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 read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is read as "Fu yi Yi er Qian san Bai si

1082. Read Number in Chinese (25)【字符串处理】——PAT (Advanced Level) Practise

题目信息 1082. Read Number in Chinese (25) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is

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, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this

【PAT甲级】1052 Linked List Sorting (25分)

1052 Linked List Sorting (25分) A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, yo

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

模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std;

1082. Read Number in Chinese (25)

题目如下: Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is read as "Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai b

【PAT甲级】1110 Complete Binary Tree (25分)

题意: 输入一个正整数N(<=20),代表结点个数(0~N-1),接着输入N行每行包括每个结点的左右子结点,'-'表示无该子结点,输出是否是一颗完全二叉树,是的话输出最后一个子结点否则输出根节点. trick: 用char输入子结点没有考虑两位数的结点??... stoi(x)可以将x转化为十进制整数 AAAAAccepted code: 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace

【PAT甲级】1044 Shopping in Mars (25 分)(前缀和,双指针)

题意: 输入一个正整数N和M(N<=1e5,M<=1e8),接下来输入N个正整数(<=1e3),按照升序输出"i-j",i~j的和等于M或者是最小的大于M的数段. 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int a[100007];int sum[100007];vector<pair<int,int> >ans;int m

【PAT甲级】1052 Linked List Sorting (25 分)

题意: 输入一个正整数N(<=100000),和一个链表的头结点地址.接着输入N行,每行包括一个结点的地址,结点存放的值(-1e5~1e5),指向下一个结点的地址.地址由五位包含前导零的正整数组成.以头结点地址开始的这条链表以值排序后得到的链表的长度和头结点,接着以升序按行输出每个结点的地址和值以及指向下一个结点的地址. trick: 题干说的postive N可是数据点4出现了N==0的数据,有些不解如果N==0应该包含的话不应该用nonnegative N吗... 数据点1包含有些结点并非在