PTA1015 德才論

題目:

宋代史學家司馬光在《資治通鑑》中有一段著名的“德才論”:“是故才德全盡謂之聖人,才德兼亡謂之愚人,德勝才謂之君子,才勝德謂之小人。凡取人之術,苟不得聖人,君子而與之,與其得小人,不若得愚人。”

現給出一批考生的德才分數,請根據司馬光的理論給出錄取排名。

輸入格式:

輸入第一行給出 3 個正整數,分別爲:N(≤10​5​​),即考生總數;L(≥60),爲錄取最低分數線,即德分和才分均不低於 L 的考生纔有資格被考慮錄取;H(<100),爲優先錄取線——德分和才分均不低於此線的被定義爲“才德全盡”,此類考生按德才總分從高到低排序;才分不到但德分到線的一類考生屬於“德勝才”,也按總分排序,但排在第一類考生之後;德才分均低於 H,但是德分不低於才分的考生屬於“才德兼亡”但尚有“德勝才”者,按總分排序,但排在第二類考生之後;其他達到最低線 L 的考生也按總分排序,但排在第三類考生之後。

隨後 N 行,每行給出一位考生的信息,包括:准考證號 德分 才分,其中准考證號爲 8 位整數,德才分爲區間 [0, 100] 內的整數。數字間以空格分隔。

輸出格式:

輸出第一行首先給出達到最低分數線的考生人數 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

簡單排序問題..

代碼:

#include<stdio.h>

#include<algorithm>

using namespace std;

struct node

{

int no;

int de;

int cai;

}stu[100005],stu1[100005],stu2[100005],stu3[100005],stu4[100005];

int n,l,h;

bool cmp(const node &a,const node &b)

{

if(a.de+a.cai!=b.de+b.cai)

return a.de+a.cai>b.de+b.cai;

else

{

if(a.de!=b.de)

return a.de>b.de;

else

return a.no<b.no;

}

}

int main()

{

scanf("%d %d %d",&n,&l,&h);

int ans=0,a,b,c;

for(int i=0;i<n;i++)

{

scanf("%d %d %d",&a,&b,&c);

if(b>=l&&c>=l)

{

stu[ans].no=a;

stu[ans].de=b;

stu[ans++].cai=c;

}

}

int ans1,ans2,ans3,ans4;

ans1=ans2=ans3=ans4=0;

for(int i=0;i<ans;i++)

{

if(stu[i].de>=h&&stu[i].cai>=h)

{

stu1[ans1].no=stu[i].no;

stu1[ans1].de=stu[i].de;

stu1[ans1++].cai=stu[i].cai;

}

if(stu[i].de>=h&&stu[i].cai<h)

{

stu2[ans2].no=stu[i].no;

stu2[ans2].de=stu[i].de;

stu2[ans2++].cai=stu[i].cai;

}

if(stu[i].de<h&&stu[i].cai<h&&stu[i].de>=stu[i].cai)

{

stu3[ans3].no=stu[i].no;

stu3[ans3].de=stu[i].de;

stu3[ans3++].cai=stu[i].cai;

}

if(stu[i].de<h&&stu[i].de<stu[i].cai)

{

stu4[ans4].no=stu[i].no;

stu4[ans4].de=stu[i].de;

stu4[ans4++].cai=stu[i].cai;

}

}

sort(stu1,stu1+ans1,cmp);

sort(stu2,stu2+ans2,cmp);

sort(stu3,stu3+ans3,cmp);

sort(stu4,stu4+ans4,cmp);

printf("%d\n",ans);

for(int i=0;i<ans1;i++)

printf("%d %d %d\n",stu1[i].no,stu1[i].de,stu1[i].cai);

for(int i=0;i<ans2;i++)

printf("%d %d %d\n",stu2[i].no,stu2[i].de,stu2[i].cai);

for(int i=0;i<ans3;i++)

printf("%d %d %d\n",stu3[i].no,stu3[i].de,stu3[i].cai);

for(int i=0;i<ans4;i++)

printf("%d %d %d\n",stu4[i].no,stu4[i].de,stu4[i].cai);

return 0;

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章