PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人)"; being less excellent but with one's virtue outweighs talent can be called a "nobleman(君子)"; being good in neither is a "fool man(愚人)"; yet a fool man is better than a "small man(小人)" who prefers talent than virtue.
Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang's theory.
Input Specification:
Each input file contains one test case. Each case first gives 3 positive integers in a line: N (≤), the total number of people to be ranked; L (≥), the lower bound of the qualified grades -- that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (<), the higher line of qualification -- that is, those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages". Those with both grades below H, but with virtue not lower than talent are considered as the "fool men". They are ranked in the same way but after the "noblemen". The rest of people whose grades both pass the L line are ranked after the "fool men".
Then N lines follow, each gives the information of a person in the format:
ID_Number Virtue_Grade Talent_Grade
where ID_Number
is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.
Output Specification:
The first line of output must give M (≤), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID's.
Sample Input:
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
Sample Output:
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
题意:
ID_Number Virtue_Grade Talent_Grade
1.只有两个分数都大于等于L才有资格排序
2.圣人就是两个分数都大于等于H....按照总分递减
3.君子就是才能低于H但是品德高于H...按照总分递减排序
4.愚人就是品德和才能低于H但是品德高于才能的
5.其余的是小人
6.排序是按品德和才能总分递减,总分相同按照品德分递减,品德分相同按照id递减
————————————————
版权声明:本文为CSDN博主「galesaur_wcy」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/galesaur_wcy/article/details/81563516
AC代码:
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int N,L,H;
int sa=,no=,fn=,sn=;
struct node{
string id;
int vir;
int tal;
};
node sage[];
node noble[];
node fm[];
node sm[];
bool cmp(node x,node y){
if(x.vir+x.tal!=y.vir+y.tal) return x.vir+x.tal>y.vir+y.tal;
else if(x.vir!=y.vir) return x.vir>y.vir;
else return x.id<y.id;
}
int main(){
cin>>N>>L>>H;
for(int i=;i<=N;i++){
string x;
int y,z;
cin>>x>>y>>z;
if(y<L||z<L) continue;
if(y>=H&&z>=H){
sage[++sa].id=x;
sage[sa].vir=y;
sage[sa].tal=z;
continue;
}
if(y>=H&&z<H){
noble[++no].id=x;
noble[no].vir=y;
noble[no].tal=z;
continue;
}
if(y<H&&z<H&&y>=z){
fm[++fn].id=x;
fm[fn].vir=y;
fm[fn].tal=z;
continue;
}
sm[++sn].id=x;
sm[sn].vir=y;
sm[sn].tal=z;
}
sort(sage+,sage++sa,cmp);
sort(noble+,noble++no,cmp);
sort(fm+,fm++fn,cmp);
sort(sm+,sm++sn,cmp);
cout<<sa+no+fn+sn<<endl;
for(int i=;i<=sa;i++) cout<<sage[i].id<<" "<<sage[i].vir<<" "<<sage[i].tal<<endl;
for(int i=;i<=no;i++) cout<<noble[i].id<<" "<<noble[i].vir<<" "<<noble[i].tal<<endl;
for(int i=;i<=fn;i++) cout<<fm[i].id<<" "<<fm[i].vir<<" "<<fm[i].tal<<endl;
for(int i=;i<=sn;i++) cout<<sm[i].id<<" "<<sm[i].vir<<" "<<sm[i].tal<<endl;
return ;
}
PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)的更多相关文章
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
- 【PAT甲级】1016 Phone Bills (25 分)(结构体排序)
题意: 输入24个正整数代表从0到23每个小时通话一分钟花费的美分.输入一个正整数N(<=1000),然后输入N组字符串,每个字符串包含客户的名字和通话的时刻以及打出或者挂断的状态. 按照字典序 ...
- 【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)
题意: 输入一个正整数N(<=10000),表示客户(对)的大小,接着输入N行数据,每行包括一对顾客到场的时间,想要玩的时间,以及是否是VIP客户.接下来输入两个正整数K,M(K<=100 ...
- 1062 Talent and Virtue (25分)(水)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- 【PAT甲级】1062 Talent and Virtue (25 分)
题意: 输入三个正整数N,L,H(N<=1E5,L>=60,H<100,H>L),分别代表人数,及格线和高水平线.接着输入N行数据,每行包括一个人的ID,道德数值和才能数值.一 ...
- PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)
题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...
- 【PAT甲级】1025 PAT Ranking (25 分)(结构体排序,MAP<string,int>映射)
题意: 输入一个正整数N(N<=100),表示接下来有N组数据.每组数据先输入一个正整数M(M<=300),表示有300名考生,接下来M行每行输入一个考生的ID和分数,ID由13位整数组成 ...
随机推荐
- DEVC++如何调试代码
DEVC++小技巧 学习C语言的同学大多都会使用DEVC++这个软件,但是在使用的时候会发现是不可以调试的,因为我们的软件默认是将调试关闭了的.下面是调试的具体方法. 点击窗口的工具按钮 点击编辑按钮 ...
- vue中读取excel中数据
安装xlsx npm install xlsx --save-dev 安装好后在需要的页面 引入插件 import xlsx from 'xlsx' 调用 $('#uploadFile').chang ...
- LG3690 【模板】Link Cut Tree 和 SDOI2008 洞穴勘测
UPD:更新了写法. [模板]Link Cut Tree 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 后接两个整数(x,y),代表询问从x到y ...
- html 实现动态在线预览word、excel、pdf等文件(方便快捷)
https://blog.csdn.net/superKM/article/details/81013304 太方便了 <iframe src='https://view.officeapps. ...
- 洛谷P2051 中国象棋【dp】
题目:https://www.luogu.org/problemnew/show/P2051 题意:n*m的格子里放炮,使他们不能互相攻击. 如果两个炮在同一行同一列并且中间还有一个棋子的话就可以攻击 ...
- Vue中使用markdown
markdown 是什么?? 1) 使用marked解析markdown文字 这个就只是解析markdown文字,并不能编辑,倒是可以从数据库中读取markdown文字进行解析,另外代码高亮还要另外解 ...
- svn优点跟缺点?
优点: 1.svn优点:集中式管理,管理方式在服务端配置好,客户端只需要同步提交即可,使用方便,操作简单,很容易就可以上手 2.在服务端统一控制好访问权限,利用代码的安全管理. 3.所有的代码以服务端 ...
- Devtool-Console
1. console面板展示 1.全屏展示 打开开发者工具(option+cmd+i),点击console的tab 2. 在其他面板展示的同时展示console面板 1)esc快捷命令 2)或者选择打 ...
- sudo 命令报 unable to resolve host 导致反应速度变慢
1 分析 1.1 字面分析,不能解析主机 1.2 由于修改了本地主机名称所导致 2 解决 2.1 打开 /etc/hosts 2.2 主机名称指向,如你的主机名为 debian 2.3 127.0. ...
- python3编程基础之一:关键字
在学习编程的过程中每种语言都会有一些特殊的字母组合在本语言中表示特定的含义,这种字母组合就是关键字.原则上,关键字是无法被重复定义的,否则,语言在应用中,就无法正确确定标号的意义了. 1.关键字的获取 ...