【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 ...
随机推荐
- 使用Id访问table对象,使用Id访问Input对象
先看例子(好吧 无意中发现 可以通过Id访问DOM元素,如div) <!DOCTYPE html> <html> <head> <meta cha ...
- 解释查询和本地查询 区分 Enumerable 和 Queryable
https://www.cnblogs.com/gosky/p/5757575.html 简单介绍:Enumerable 和 Queryable 他们都是静态类,位于命名控件 System.Linq下 ...
- redis集群(Sentinel)
问题 Redis 主哨兵模式是如何保证高可用的 主要依赖主哨兵的发现故障和故障转移 概述 本文假设读者对redis 的主从复制已经进行了了解 . Redis 主哨兵集群为Redis 提供了高可用,即高 ...
- Go流程结构(if)
一.程序的流程结构 程序的流程控制结构一共有三种:顺序结构,选择结构,循环结构. 顺序结构:从上向下,逐行执行. 选择结构:条件满足,某些代码才会执行.0-1次 分支语句:if,switch,sele ...
- ALSA driver--Asoc
https://blog.csdn.net/zyuanyun/article/details/59170418 ALSA Asoc框架如下图: Asoc分为machine,platform,codec ...
- 每天进步一点点------CORDIC (一)
三角函数计算,Cordic 算法入门 三角函数的计算是个复杂的主题,有计算机之前,人们通常通过查找三角函数表来计算任意角度的三角函数的值.这种表格在人们刚刚产生三角函数的概念的时候就已经有了,它们通常 ...
- 多租户SaaS平台的数据库方案
1.1 多租户是什么 多租户技术(Multi-TenancyTechnology)又称多重租赁技术:是一种软件架构技术,是实现如何在多用户环境下 (此处的多用户一般是面向企业用户)共用相同的系统或程序 ...
- 加壳&脱壳 - 前言(4.17更新)
0x00 闲谈 最近打算学习学习加壳脱壳相关的知识,大致会有以下几个部分 1.upx壳的加壳原理及脱壳方法 --UPX压缩壳的工作原理 --脱upx壳--初试--单步追踪 -- 0x01 参考链接 1 ...
- RocketMq-粪发涂墙1.0
角色 说明 Producer 生产者,用于将消息发送到RocketMQ,生产者本身既可以是生成消息,也可以对外提供接口,由外部来调用接口,再由生产者将受到的消息发送给MQ. Consumer 消费者, ...
- Linux01——常用命令
帮助命令: man 一行一行显示 ,按下enter键就向下显示一行,按q退出 --help 全部显示 日期类:date ,cal 显示当前目录:pwd 切换目录:cd(***重点***) cd .. ...