B1015. 德才论 (25')

来源:互联网 发布:淘宝导航尺寸是多少 编辑:程序博客网 时间:2024/06/03 20:29
宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”


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


输入格式:


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


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


输出格式:


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


输入样例:
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
输出样例:
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79

10000001 64 90


解题思路:

题目的思路还是很清晰的,就是给学生按指定规则就行分类排序,最后输出。

学生类别分为5类,第一类(德才分均不低于h),第二类(德分不低于h,才分低于h),第三类(德才分均低于h,但德分不低于才分),第五类(德才分均低于l),剩余的为第四类(较复杂,所以放到最后)。

排序规则是先按分类升序排列,同类别再按总分降序排列,同总分再按德分降序排列,同德分再按准考证升序排列。


#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n, l, h;//学生结构体 struct Student {char id[10];//8位学号 int dScore;//德分 int cScore;//才分 int sum;//总分 int level;//类别 }stu[100010];//比较规则 bool cmp(Student s1, Student s2) {if(s1.level != s2.level) return s1.level < s2.level;else if(s1.sum != s2.sum) return s1.sum > s2.sum;else if(s1.dScore != s2.dScore) return s1.dScore > s2.dScore;else return strcmp(s1.id, s2.id) < 0;}int main() {int cnt = 0;scanf("%d %d %d", &n, &l, &h);for(int i = 0; i < n; i++) {scanf("%s %d %d", stu[i].id, &stu[i].dScore, &stu[i].cScore);stu[i].sum = stu[i].dScore + stu[i].cScore; //总分 if(stu[i].dScore >= l && stu[i].cScore >= l) cnt++;//统计合格人数 //给学生分类 if(stu[i].dScore < l || stu[i].cScore < l) stu[i].level = 5;else if(stu[i].dScore >= h && stu[i].cScore >= h)stu[i].level = 1;else if(stu[i].dScore >= h && stu[i].cScore < h)stu[i].level = 2;else if(stu[i].dScore >= stu[i].cScore)stu[i].level = 3;else stu[i].level = 4;} sort(stu, stu + n, cmp);//排序printf("%d\n", cnt); for(int i = 0; i < cnt; i++) {printf("%s %d %d\n", stu[i].id, stu[i].dScore, stu[i].cScore);}return 0;} 


0 0
原创粉丝点击