思路:
- 通过考生分数判断考生属于第几类(level()函数)
- 不同类别的考生比类别,类别越高排名越靠前
- 相同类别的考生比总分降序>德分降序>准考证号升序
#include<iostream>
#include<algorithm>
using namespace std;
struct student{
int id;
int de;
int cai;
}stu[100001];
int n,l,h;
int level(student a){
if(a.de>=h&&a.cai>=h) return 4;
else if(a.de>=h&&a.cai<h&&a.cai>=l) return 3;
else if(a.de>=a.cai&&a.cai<h&&a.cai>=l&&a.de<h&&a.de>=l) return 2;
else if(a.de<l||a.cai<l) return 0;
else return 1;
}
bool cmp(student a,student b){
int a_all=a.de+a.cai,b_all=b.de+b.cai;
if(level(a)!=level(b)) return level(a)>level(b); //不同类别考生比等级
else{ //相同类别考生比总分降序>德分降序>准考证号升序
if(a_all==b_all){
if(a.de==b.de){
return a.id<b.id;
}else{
return a.de>b.de;
}
}else{
return a_all>b_all;
}
}
}
int main(){
cin>>n>>l>>h;
int uplow=0;
for(int i=0;i<n;i++){
cin>>stu[i].id>>stu[i].de>>stu[i].cai;
if(stu[i].de>=l&&stu[i].cai>=l) uplow++;
}
sort(stu,stu+n,cmp);
cout<<uplow<<endl;
for(int i=0;i<n;i++){
if(stu[i].de<l||stu[i].cai<l) continue;
cout<<stu[i].id<<" "<<stu[i].de<<" "<<stu[i].cai;
if(i!=n-1) cout<<endl;
}
}