描述
宋代史學(xué)家司馬光在《資治通鑒》中有一段著名的“德才論”:“是故才德全盡謂之圣人,才德兼亡謂之愚人燕雁,德勝才謂之君子诞丽,才勝德謂之小人。凡取人之術(shù)拐格,茍不得圣人僧免,君子而與之,與其得小人捏浊,不若得愚人懂衩。”
現(xiàn)給出一批考生的德才分?jǐn)?shù)金踪,請(qǐng)根據(jù)司馬光的理論給出錄取排名浊洞。
輸入格式:
輸入第1行給出3個(gè)正整數(shù),分別為:N(<=105)胡岔,即考生總數(shù)法希;L(>=60),為錄取最低分?jǐn)?shù)線姐军,即德分和才分均不低于L的考生才有資格被考慮錄忍摹;H(<100)奕锌,為優(yōu)先錄取線——德分和才分均不低于此線的被定義為“才德全盡”著觉,此類考生按德才總分從高到低排序;才分不到但德分到線的一類考生屬于“德勝才”惊暴,也按總分排序饼丘,但排在第一類考生之后;德才分均低于H辽话,但是德分不低于才分的考生屬于“才德兼亡”但尚有“德勝才”者肄鸽,按總分排序,但排在第二類考生之后油啤;其他達(dá)到最低線L的考生也按總分排序典徘,但排在第三類考生之后。
隨后N行益咬,每行給出一位考生的信息逮诲,包括:準(zhǔn)考證號(hào)、德分、才分梅鹦,其中準(zhǔn)考證號(hào)為8位整數(shù)裆甩,德才分為區(qū)間[0, 100]內(nèi)的整數(shù)。數(shù)字間以空格分隔齐唆。
輸出格式:
輸出第1行首先給出達(dá)到最低分?jǐn)?shù)線的考生人數(shù)M嗤栓,隨后M行,每行按照輸入格式輸出一位考生的信息箍邮,考生按輸入中說明的規(guī)則從高到低排序茉帅。當(dāng)某類考生中有多人總分相同時(shí),按其德分降序排列媒殉;若德分也并列担敌,則按準(zhǔn)考證號(hào)的升序輸出摔敛。
輸入樣例:
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
不會(huì)做廷蓉, copy回來慢慢理解
#include <stdio.h>
#include <stdlib.h>
typedef struct info_ {
int id;
int de;
int cai;
int sum; // 總分
int type;
} Info;
int get_type(int de, int cai);
int compar(const void *pa, const void *pb);
int high, low;
int main(void)
{
int size;
scanf("%d %d %d", &size, &low, &high);
Info *xs = (Info*)malloc(size * sizeof(Info));
int count = 0;
int i;
for (i=0; i<size; i++){
scanf("%d %d %d", &xs[i].id, &xs[i].de, &xs[i].cai);
xs[i].sum = xs[i].de + xs[i].cai;
xs[i].type = get_type(xs[i].de, xs[i].cai);
if (xs[i].type != 5) {
count++;
}
}
printf("%d\n", count);
qsort(xs, size, sizeof(Info), compar);
for (i=0; i<count; i++){
printf("%d %d %d\n", xs[i].id, xs[i].de, xs[i].cai);
printf("type=%d, sum=%d, de=%d\n", xs[i].type, xs[i].sum, xs[i].de);
}
free(xs);
return 0;
}
int compar(const void *pa, const void *pb)
{
Info a = *(Info *)pa;
Info b = *(Info *)pb;
int ret;
if (a.type == b.type){
if (a.sum == b.sum){
if (a.de == b.de){
ret = a.id - b.id;
} else {
ret = b.de - a.de;
}
} else {
ret = b.sum - a.sum;
}
} else {
ret = a.type - b.type;
}
return ret;
}
int get_type(int de, int cai)
{
int type;
if (de >= high){
if (cai >= high){ // 徳才優(yōu)秀
type = 1;
} else if (cai >= low) { // 徳優(yōu)秀,才及格
type = 2;
} else { // 徳優(yōu)秀马昙,才不及格
type = 5;
}
} else if ( de >= low){
if (cai >= high){ // 徳及格桃犬,才優(yōu)秀
type = 4;
} else if (cai >= low){
if (de >= cai){ // 才德及格,但是徳大于才
type = 3;
} else { // 徳才及格
type = 4;
}
} else { // 徳及格才不及格
type = 5;
}
} else { // 徳不及格
type = 5;
}
return type;
}