1015 德才论 (25分)
- 分四个等级的排序,想简化的朋友可以用结构体数组容器存储啦~
#include<iostream>
#include<vector>
#include<ctype.h>
#include<algorithm>
#include<sstream>
#include<string>
#include<cstdio>
using namespace std;
/*此类考生按德才总分从高到低排序*/
/*才分不到但德分到线的一类考生
也按总分排序,但排在第一类考生之后*/
/*德才分均低于H,但是德分不低于才分的考生,
按总分排序,但排在第二类考生之后*/
/*其他达到最低线 L 的考生也按总分排序,但排在第三类考生之后*/
struct Node{
int num, grade1,grade2,sum;
};
int cnt=0;
vector<Node> stu1;
vector<Node> stu2;
vector<Node> stu3;
vector<Node> stu4;
bool cmp(Node a,Node b){
if(a.sum!=b.sum){
return a.sum>b.sum;
}else if(a.grade1!=b.grade1){
return a.grade1>b.grade1;
}else{
return a.num<b.num;
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,L,H; cin>>n>>L>>H;
for(int i=1;i<=n;i++){
int num,grade1,grade2;
cin>>num>>grade1>>grade2;
if(grade1>=L&&grade2>=L){
cnt++;int sum=grade1+grade2;
if(grade1>=H&&grade2>=H){
stu1.push_back({num,grade1,grade2,sum});
continue;
}
if(grade1>=H&&grade2<H){
stu2.push_back({num,grade1,grade2,sum});
continue;
}
if(grade1<H&&grade2<H&&grade1>=grade2){
stu3.push_back({num,grade1,grade2,sum});
continue;
}
stu4.push_back({num,grade1,grade2,sum});
}
}
sort(stu1.begin(),stu1.end(),cmp);
sort(stu2.begin(),stu2.end(),cmp);
sort(stu3.begin(),stu3.end(),cmp);
sort(stu4.begin(),stu4.end(),cmp);
cout<<cnt<<"\n";
for(int i=0;i<stu1.size();i++){
cout<<stu1[i].num<<" "<<stu1[i].grade1<<" "<<stu1[i].grade2<<"\n";
}
for(int i=0;i<stu2.size();i++){
cout<<stu2[i].num<<" "<<stu2[i].grade1<<" "<<stu2[i].grade2<<"\n";
}
for(int i=0;i<stu3.size();i++){
cout<<stu3[i].num<<" "<<stu3[i].grade1<<" "<<stu3[i].grade2<<"\n";
}
for(int i=0;i<stu4.size();i++){
cout<<stu4[i].num<<" "<<stu4[i].grade1<<" "<<stu4[i].grade2<<"\n";
}
return 0;
}