PAT1015. 德才论 (25)

来源:互联网 发布:明保理和暗保理 知乎 编辑:程序博客网 时间:2024/05/21 20:30

宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”

现给出一批考生的德才分数,请根据司马光的理论给出录取排名。

输入格式:

输入第1行给出3个正整数,分别为:N(<=105),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线L的考生也按总分排序,但排在第三类考生之后。

随后N行,每行给出一位考生的信息,包括:准考证号、德分、才分,其中准考证号为8位整数,德才分为区间[0, 100]内的整数。数字间以空格分隔。

输出格式:

输出第1行首先给出达到最低分数线的考生人数M,随后M行,每行按照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。

输入样例:
14 60 8010000001 64 9010000002 90 6010000011 85 8010000003 85 8010000004 80 8510000005 82 7710000006 83 7610000007 90 7810000008 75 7910000009 59 9010000010 88 4510000012 80 10010000013 90 9910000014 66 60
输出样例:
1210000013 90 9910000012 80 10010000003 85 8010000011 85 8010000004 80 8510000007 90 7810000006 83 7610000005 82 7710000002 90 6010000014 66 6010000008 75 7910000001 64 90
#include<iostream>#include<vector>#include<algorithm>#include<cstdio>using namespace std;struct Student{ int id_number; int virtue; int talent;};bool score_compare(const Student& stu1,const Student& stu2){if(stu1.virtue+stu1.talent==stu2.virtue+stu2.talent){if(stu1.virtue==stu2.virtue)return stu1.id_number<stu2.id_number;return stu1.virtue>stu2.virtue;}return stu1.virtue+stu1.talent>stu2.virtue+stu2.talent;}void show_stu(Student& stu){printf("%d %d %d\n",stu.id_number,stu.virtue,stu.talent);}int main(){int num,prior_score,pass_score;cin>>num>>pass_score>>prior_score;if(num<=0 || num>100000|| pass_score<60||prior_score<0 || prior_score>=100 || prior_score<pass_score)return -1;vector<Student> stu1;vector<Student> stu2;vector<Student> stu3;vector<Student> stu4;Student temp;for(int i=0;i<num;++i){scanf("%d%d%d",&temp.id_number,&temp.virtue,&temp.talent);if(temp.virtue>=pass_score && temp.talent>=pass_score){if(temp.virtue>=prior_score && temp.talent>=prior_score)stu1.push_back(temp);else if(temp.virtue>=prior_score)stu2.push_back(temp);else if(temp.virtue>=temp.talent)stu3.push_back(temp);else stu4.push_back(temp);}}sort(stu1.begin(),stu1.end(),score_compare);sort(stu2.begin(),stu2.end(),score_compare);sort(stu3.begin(),stu3.end(),score_compare);sort(stu4.begin(),stu4.end(),score_compare);cout<<stu1.size()+stu2.size()+stu3.size()+stu4.size()<<endl;for_each(stu1.begin(),stu1.end(),show_stu);for_each(stu2.begin(),stu2.end(),show_stu);for_each(stu3.begin(),stu3.end(),show_stu);for_each(stu4.begin(),stu4.end(),show_stu);return 0;}


 

0 0