宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”
现给出一批考生的德才分数,请根据司马光的理论给出录取排名。
输入格式:
输入第一行给出 3 个正整数,分别为:N(≤105),即考生总数;L(≥60),为录取最低分数线,即德分和才分均不低于 L 的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到优先录取线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于 H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线 L 的考生也按总分排序,但排在第三类考生之后。
随后 N 行,每行给出一位考生的信息,包括:准考证号 德分 才分
,其中准考证号
为 8 位整数,德才分为区间 [0, 100] 内的整数。数字间以空格分隔。
输出格式:
输出第一行首先给出达到最低分数线的考生人数 M,随后 M 行,每行按照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。
代码:
//
// Created by skywircL on 4/18/24.
//
#include<iostream>
#include "algorithm"
#include "cstring"
struct student {
char id[15];
int de;
int cai;
int status;
}stu[100100];
bool cmp (student a,student b) {
return a.status < b.status;
}
bool cmp2 (student a,student b) {
if (a.cai +a.de != b.cai +b.de) return a.cai +a.de > b.cai +b.de ;
else {
if(a.de != b.de) return a.de>b.de;
else return strcmp(a.id,b.id)<0;
}
}
int main() {
int n,l ,h,n1=0,n2=0,n3=0,n4=0,capable=0;
scanf("%d %d %d",&n,&l,&h);
for (int i = 0; i < n; ++i) {
scanf("%s %d %d",stu[capable].id,&stu[capable].de,&stu[capable].cai);
// judge
if (stu[capable].de<l || stu[capable].cai < l) {
continue;
}
n4++;
stu[capable].status = 4;
if (stu[capable].de>=h && stu[capable].cai >= h) {
n1++;
stu[capable].status = 1;
n4--;
}
if (stu[capable].de>=h && stu[capable].cai < h) {
n2++;
stu[capable].status = 2;
n4--;
}
if (stu[capable].de<h && stu[capable].cai < h&&(stu[capable].de>= stu[capable].cai)) {
n3++;
stu[capable].status = 3;
n4--;
}
capable ++;
}
std::sort(stu,stu+capable,cmp);
std::sort(stu,stu+n1,cmp2);
std::sort(stu+n1,stu+n1+n2,cmp2);
std::sort(stu+n1+n2,stu+n1+n2+n3,cmp2);
std::sort(stu+n1+n2+n3,stu+n1+n2+n3+n4,cmp2);
printf("%d\n",capable);
for (int i = 0; i < capable; ++i) {
printf("%s %d %d\n",stu[i].id,stu[i].de,stu[i].cai );
}
return 0;
}