1012. The Best Rank (25)

来源:互联网 发布:连锁店软件 编辑:程序博客网 时间:2024/06/05 05:34
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".


IDEA

1.需要注意的是,分数相同其排名也相同


#include<iostream>#include<cstring>#include<vector>#include<algorithm>using namespace std;struct Stu{string id;int c,m,e;int a;int rank;};int cmp_c(Stu stu1,Stu stu2){return stu1.c>stu2.c;}int cmp_m(Stu stu1,Stu stu2){return stu1.m>stu2.m;}int cmp_e(Stu stu1,Stu stu2){return stu1.e>stu2.e;}int cmp_a(Stu stu1,Stu stu2){return stu1.a>stu2.a;}int main(){int n,m;cin>>n>>m;Stu stu[2001];for(int i=0;i<n;i++){cin>>stu[i].id>>stu[i].c>>stu[i].m>>stu[i].e;stu[i].a=stu[i].c+stu[i].m+stu[i].e;stu[i].rank=99999;}for(int i=0;i<m;i++){string id;cin>>id;int flag=0;for(int i=0;i<n;i++){if(stu[i].id==id){flag=1;}}if(flag==0){cout<<"N/A"<<endl;continue;}int rank[4]={0}; //对a排序sort(stu,stu+n,cmp_a);for(int i=0;i<n;i++){if(i==0){stu[i].rank=1;}else if(stu[i].a==stu[i-1].a){stu[i].rank=stu[i-1].rank;}else{stu[i].rank=i+1;}}for(int i=0;i<n;i++){if(stu[i].id==id){rank[0]=stu[i].rank;break;}}//对c排序 sort(stu,stu+n,cmp_c);for(int i=0;i<n;i++){if(i==0){stu[i].rank=1;}else if(stu[i].c==stu[i-1].c){stu[i].rank=stu[i-1].rank;}else{stu[i].rank=i+1;}}for(int i=0;i<n;i++){if(stu[i].id==id){rank[1]=stu[i].rank;break;}}//对m排序sort(stu,stu+n,cmp_m);for(int i=0;i<n;i++){if(i==0){stu[i].rank=1;}else if(stu[i].m==stu[i-1].m){stu[i].rank=stu[i-1].rank;}else{stu[i].rank=i+1;}}for(int i=0;i<n;i++){if(stu[i].id==id){rank[2]=stu[i].rank;break;}}//对e排序sort(stu,stu+n,cmp_e);for(int i=0;i<n;i++){if(i==0){stu[i].rank=1;}else if(stu[i].e==stu[i-1].e){stu[i].rank=stu[i-1].rank;}else{stu[i].rank=i+1;}}for(int i=0;i<n;i++){if(stu[i].id==id){rank[3]=stu[i].rank;break;}}int min=2001,index=0;for(int i=0;i<4;i++){//cout<<rank[i]<<" ";if(min>rank[i]){min=rank[i];index=i;}}//cout<<endl;cout<<min;switch(index){case 0:cout<<" "<<"A";break;case 1:cout<<" "<<"C";break;case 2:cout<<" "<<"M";break;case 3:cout<<" "<<"E";break;}cout<<endl;}return 0;}


0 0
原创粉丝点击