【PAT甲级】1062 Talent and Virtue (25 分)
题意:
输入三个正整数N,L,H(N<=1E5,L>=60,H<100,H>L),分别代表人数,及格线和高水平线。接着输入N行数据,每行包括一个人的ID,道德数值和才能数值。一个人的道德和才能都不低于H时为圣人,道德不低于H才能不低于L时为贵族,道德和才能都不低于L且道德不低于才能时为愚者,道德和才能都不低于L且道德低于才能时为小人(圣人优先判断,圣人的才能可以高于道德)。分别在自己的所在的群体内排序,依照道德才能总和降序排序,第二优先为才能的数值降序,第三优先为id的升序。按照题意输出排序的总人数以及输出它们的信息。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct student{
string id;
int v,t;
int sum;
};
student sage[],noble[],fool[],small[];
bool cmp(student a,student b){
if(a.sum!=b.sum)
return a.sum>b.sum;
if(a.v!=b.v)
return a.v>b.v;
return a.id<b.id;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,l,h;
cin>>n>>l>>h;
int cnt1=,cnt2=,cnt3=,cnt4=;
for(int i=;i<=n;++i){
string id;
cin>>id;
int v,t;
cin>>v>>t;
if(v>=h&&t>=h){
sage[++cnt1].id=id;
sage[cnt1].v=v;
sage[cnt1].t=t;
sage[cnt1].sum=v+t;
}
else if(v>=h&&t>=l){
noble[++cnt2].id=id;
noble[cnt2].v=v;
noble[cnt2].t=t;
noble[cnt2].sum=v+t;
}
else if(v>=l&&t>=l&&v>=t){
fool[++cnt3].id=id;
fool[cnt3].v=v;
fool[cnt3].t=t;
fool[cnt3].sum=v+t;
}
else if(v>=l&&t>=l&&v<t){
small[++cnt4].id=id;
small[cnt4].v=v;
small[cnt4].t=t;
small[cnt4].sum=v+t;
}
}
sort(sage+,sage++cnt1,cmp);
sort(noble+,noble++cnt2,cmp);
sort(fool+,fool++cnt3,cmp);
sort(small+,small++cnt4,cmp);
cout<<cnt1+cnt2+cnt3+cnt4<<"\n";
for(int i=;i<=cnt1;++i)
cout<<sage[i].id<<" "<<sage[i].v<<" "<<sage[i].t<<"\n";
for(int i=;i<=cnt2;++i)
cout<<noble[i].id<<" "<<noble[i].v<<" "<<noble[i].t<<"\n";
for(int i=;i<=cnt3;++i)
cout<<fool[i].id<<" "<<fool[i].v<<" "<<fool[i].t<<"\n";
for(int i=;i<=cnt4;++i)
cout<<small[i].id<<" "<<small[i].v<<" "<<small[i].t<<"\n";
return ;
}
【PAT甲级】1062 Talent and Virtue (25 分)的更多相关文章
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
- 1062 Talent and Virtue (25分)(水)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...
- 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise
题目信息 1062. Talent and Virtue (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B About 900 years ago, a Chine ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- 1062 Talent and Virtue (25)
/* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- PAT甲级——1130 Infix Expression (25 分)
1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...
- PAT 甲级 1074 Reversing Linked List (25 分)(链表部分逆置,结合使用双端队列和栈,其实使用vector更简单呐)
1074 Reversing Linked List (25 分) Given a constant K and a singly linked list L, you are supposed ...
- PAT 甲级 1086 Tree Traversals Again (25分)(先序中序链表建树,求后序)***重点复习
1086 Tree Traversals Again (25分) An inorder binary tree traversal can be implemented in a non-recu ...
随机推荐
- Http接口安全设计
1. 完全开放 2. 基本验证 appid(企业唯一标识)+args(请求参数)->sign(摘要). 3. 时效控制 appid+args+timestamp(时间戳)->sign. ...
- 各技能DBC参数
推荐你 通过 引擎的帮助文件查找标准魔法DB 下面是 部分hero引擎的标准魔法DB 34,解毒术,2,26,16,0,0,0,0,0,2,42,50,44,100,46,200,40,, 35,老 ...
- my codestyle
代码风格 缩进 缩进采用4个空格或tab. 原则是:如果地位相等,则不需要缩进:如果属于某一个代码的内部代码就需要缩进. 变量命名 变量命名遵守遵从驼峰命名法,统一使用lowerCamelCase风格 ...
- 【vue store的使用方法】(this.$store.state this.$store.getters this.$store.dispatch this.$store.commit)
vue 页面文件 <template> <div> {{this.$store.state.count}}<br/> {{count}}<br/> {{ ...
- PMP概略学习下--主体内容
4 知识主体 4.1 主要知识简介 PMP所有的知识围绕五大过程组和十大知识领域展开.五大过程组包括启动.规划.执行.监控.结尾.启动的内容主要是定义项目或阶段.获得授权以及正式开始:规划的内容主要 ...
- Docker 基本命令和使用
Docker 基本命令 systemctl start docker : 启动 Docker systemctl stop docker : 停止 Docker systemctl restart d ...
- Flask 教程 第十六章:全文搜索
本文翻译自The Flask Mega-Tutorial Part XVI: Full-Text Search 这是Flask Mega-Tutorial系列的第十六部分,我将在其中为Microblo ...
- 2019冬季PAT甲级第三题
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; ]; int main(){ ...
- 每天进步一点点------Sobel算子(2)
转载 http://blog.csdn.net/tianhai110 索贝尔算子(Sobel operator)主要用作边缘检测,在技术上,它是一离散性差分算子,用来运算图像亮度函数的灰度之近似值. ...
- mysql开启远程访问及相关权限控制
开启mysql远程访问: 授予用户user 密码 passwd 所有权限 所有主机IP可访问 授权语句:Grant <权限> on 表名[(列名)] to 用户 With grant op ...