题意:

输入三个正整数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 分)的更多相关文章

  1. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

  2. 1062 Talent and Virtue (25分)(水)

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

  3. 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 ...

  4. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  5. 1062 Talent and Virtue (25)

    /* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...

  6. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  7. PAT甲级——1130 Infix Expression (25 分)

    1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...

  8. 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 ...

  9. PAT 甲级 1086 Tree Traversals Again (25分)(先序中序链表建树,求后序)***重点复习

    1086 Tree Traversals Again (25分)   An inorder binary tree traversal can be implemented in a non-recu ...

随机推荐

  1. STA之RC Corner再论

    Q:RC-Corner跟PVT怎么组合? A:通常的组合:   Q:通常说的ttcorner指的是啥? A:@孟时光 ttcorner是指管子在tt+RCtyp吧. Typesof corners W ...

  2. js实现页面的秒数倒计时

    <button name="vcode_mail" class="btn btn-default" type="button" id= ...

  3. css transform 2D3D转换

    2D转换 translate 移动 <style> div{ width: 100px; height: 100px; } .box{ border: 1px dashed red; fl ...

  4. 8.14-T2捕老鼠(cat)

    题目大意 有 N 个仓库,排成了一排,编号为 1-N.假设在第 i 个仓库点燃艾条,烟雾就会充满该仓库,并向左右扩散Ai的距离,接着所有|i-j|<=Ai的仓库 j 的老鼠被消灭.最少需要多少支 ...

  5. opencv:形态学操作-腐蚀与膨胀

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...

  6. Java进阶学习(5)之设计原则(上)

    设计原则 城堡游戏 扩展 字符串被分割 String line = in.nextLine(); String[] words = line.split(" "); 消除代码复制 ...

  7. php的str_pad()函数

    实例 填充字符串的右侧,到30个字符的新长度 <?php $str = "Hello World"; echo str_pad($str,30,"."); ...

  8. CSH while read

  9. 关于XShell&XFtp

    今天在开发的时候要打包一个东东到测试服务器去,突然发现xftp用不了,然后各种下载破解.绿色版 结果都是一堆广告,原来这个xshell支持民用版,无需破解就能下载使用,这里小小的记录下 一.  前言 ...

  10. 负环--spfa

    洛谷板子题 负环?是有负权边的环还是一个边权之和为负的环? 还没有准确的定义(那就先忽略吧qwq 判断负环的方法: 暴力枚举/spfa/mellman—ford/奇怪的贪心/超神的搜索 可惜我只会sp ...