1015. 德才论

来源:互联网 发布:大数据中学生阅读答案 编辑:程序博客网 时间:2024/06/07 12:22

1015. 德才论 (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Li

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

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

输入格式:

输入第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<stdio.h>typedef struct {  int id, d, c, total, class;}Student;int cmp(const void* _a, const void* _b) {  Student* a = (Student*)_a;  Student* b = (Student*)_b;  if (a->class != b->class) return a->class - b->class;  else if (a->total != b->total) return b->total - a->total;  else if (a->d != b->d) return b->d - a->d;  else return a->id - b->id;}int main(){  int N, L, H, M = 0;  scanf("%d %d %d", &N, &L, &H);  Student stu[N];  int i;  for (i = 0; i<N; i++) {    scanf("%d %d %d", &stu[i].id, &stu[i].d, &stu[i].c);    stu[i].total = stu[i].d + stu[i].c;    if (stu[i].d >= L&&stu[i].c >= L) {      M++;      if (stu[i].d >= H&&stu[i].c >= H) stu[i].class = 1;      else if (stu[i].c<H&&stu[i].d >= H) stu[i].class = 2;      else if (stu[i].d<H&&stu[i].d<H, stu[i].d >= stu[i].c) stu[i].class = 3;      else stu[i].class = 4;    }    else {      stu[i].class = 5;    }  }  qsort(stu, N, sizeof(Student), cmp);  printf("%d\n", M);  for (i = 0; i<M; i++) {    printf("%d %d %d\n", stu[i].id, stu[i].d, stu[i].c);  }  return 0;}
0 0