国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

1012. The Best Rank (25)

2019-11-08 18:46:36
字體:
供稿:網(wǎng)友

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C PRogramming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.

For example, The grades of C, M, E and A - Average of 4 students are given as the following:

StudentID C M E A 310101 98 85 88 90 310102 70 95 88 84 310103 82 87 94 88 310104 91 91 91 91 Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

Input

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

Output

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

If a student is not on the grading list, simply output “N/A”.

Sample Input 5 6 310101 98 85 88 310102 70 95 88 310103 82 87 94 310104 91 91 91 310105 85 90 90 310101 310102 310103 310104 310105 999999 Sample Output 1 C 1 M 1 E 1 A 3 A N/A

//方法1:#include<cstdio>#include<algorithm>#include<map>using namespace std;const int maxn=2010;struct Student{ int id; int c,m,e,a; int rank[4]; int high_rank,idx;}stu[maxn];int A[maxn],C[maxn],M[maxn],E[maxn];char Sig[4]={'A','C','M','E'};map<int,Student> mp;int searchHigh(int rank[],int& high_rank){ if(rank[0]<=rank[1]&&rank[0]<=rank[2]&&rank[0]<=rank[3]){ high_rank=rank[0]; return 0; }else if(rank[1]<=rank[0]&&rank[1]<=rank[2]&&rank[1]<=rank[3]){ high_rank=rank[1]; return 1; }else if(rank[2]<=rank[0]&&rank[2]<=rank[1]&&rank[2]<=rank[3]){ high_rank=rank[2]; return 2; }else{ high_rank=rank[3]; return 3; }}int main(){ int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;i++){ int id,c,m,e,a; scanf("%d%d%d%d",&id,&c,&m,&e); A[i]=(c+m+e),C[i]=c,M[i]=m,E[i]=e; stu[i].id=id; stu[i].c=c; stu[i].m=m; stu[i].e=e; stu[i].a=(c+m+e); } sort(A,A+n); sort(C,C+n);sort(M,M+n);sort(E,E+n);// printf("每個學(xué)生的排名:/n"); for(int i=0;i<n;i++){ stu[i].rank[0]=n-(upper_bound(A,A+n,stu[i].a)-A)+1; stu[i].rank[1]=n-(upper_bound(C,C+n,stu[i].c)-C)+1; stu[i].rank[2]=n-(upper_bound(M,M+n,stu[i].m)-M)+1; stu[i].rank[3]=n-(upper_bound(E,E+n,stu[i].e)-E)+1; int k=0; for(int j=0;j<4;j++){//尋找最高排名,也可用下面的searchHigh()方法 if(stu[i].rank[j]<stu[i].rank[k]){ k=j; } } stu[i].high_rank=stu[i].rank[k]; stu[i].idx=k;// stu[i].idx=searchHigh(stu[i].rank,stu[i].high_rank);// printf("%d %d %d %d 最高排名:%d/n",stu[i].rank[0],stu[i].rank[1],stu[i].rank[2],stu[i].rank[3],stu[i].high_rank); } for(int i=0;i<n;i++){ mp[stu[i].id]=stu[i]; } for(int i=0;i<m;i++){ int id; scanf("%d",&id); if(mp.find(id)==mp.end()){ printf("N/A/n"); }else{ printf("%d %c/n",mp[id].high_rank,Sig[mp[id].idx]); } } return 0; } return 0; } //方法2:#include<cstdio>#include<algorithm>using namespace std;const int maxn=2010;const int maxid=1000000;struct Student{ int id; int grade[4];//記a,c,m,e四個科目的分?jǐn)?shù) }stu[maxn];int now;int rank[maxid][4];//rank[id]為學(xué)生id四個科目的排名的數(shù)組char course[4]={'A','C','M','E'};bool cmp(Student a,Student b){ return a.grade[now]>b.grade[now];}int main(){ int n,m; scanf("%d %d",&n,&m); for(int i=0;i<n;i++){ int id,a,c,m,e; scanf("%d%d%d%d",&id,&c,&m,&e); a=c+m+e; stu[i].id=id; stu[i].grade[0]=a; stu[i].grade[1]=c; stu[i].grade[2]=m; stu[i].grade[3]=e; } for(now=0;now<4;now++){//分別以a,c,m,e為依據(jù)對學(xué)生進行排序,第一輪以每個學(xué)生的a為依據(jù)進行排序,第二輪依據(jù)c..... sort(stu,stu+n,cmp); rank[stu[0].id][now]=1; for(int i=1;i<n;i++){//對于每個學(xué)生 if(stu[i].grade[now]==stu[i-1].grade[0]){ rank[stu[i].id][now]=rank[stu[i-1].id][now];//rank[id][now]表示學(xué)號為id的學(xué)生,now科目的排名 }else{ rank[stu[i].id][now]=i+1; } } } for(int i=0;i<m;i++){ int id; scanf("%d",&id); if(rank[id][0]==0){ printf("N/A/n"); }else{ int k=0; for(int j=0;j<4;j++){ if(rank[id][j]<rank[id][k]){ k=j; } } printf("%d %c/n",rank[id][k],course[k]); } } return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 江城| 财经| 丹阳市| 宣城市| 新野县| 武邑县| 大姚县| 南丰县| 湖南省| 阳高县| 木兰县| 吉木乃县| 双城市| 凌海市| 论坛| 青铜峡市| 卓尼县| 宣化县| 登封市| 苍梧县| 屏南县| 黄石市| 镇宁| 灵璧县| 岗巴县| 乌拉特后旗| 辽宁省| 宜章县| 奇台县| 天津市| 勃利县| 泽州县| 慈溪市| 内丘县| 曲水县| 罗山县| 澜沧| 中超| 万荣县| 林甸县| 上杭县|