1012. The Best Rank (25)

来源:互联网 发布:依文男装淘宝旗舰店 编辑:程序博客网 时间:2024/05/18 00:03

1012. The Best Rank (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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  A310101     98 85 88 90310102     70 95 88 84310103     82 87 94 88310104     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 6310101 98 85 88310102 70 95 88310103 82 87 94310104 91 91 91310105 85 90 90310101310102310103310104310105999999
Sample Output
1 C1 M1 E1 A3 AN/A
求每个人的A、C、M、E的最前排名,若最前排名相同时优先性为A>C>M>E。

#include<iostream>#include<vector>#include<algorithm>using namespace std;struct Rank{int Student_ID;int C,M,E,A;};bool Comp(const int &a,const int &b){return a>b;}int main(){int i,N,M,student_id,average;Rank stu;vector<int> Average,C,Math,E;vector<Rank> s;vector<Rank>::iterator it;cin>>N>>M;for(i=0;i<N;i++){cin>>stu.Student_ID>>stu.C>>stu.M>>stu.E;s.push_back(stu);average=stu.C+stu.M+stu.E;//平均分比较时:总分相当于平均分Average.push_back(average);C.push_back(stu.C);Math.push_back(stu.M);E.push_back(stu.E);}sort(Average.begin(),Average.end(),Comp);sort(C.begin(),C.end(),Comp);sort(Math.begin(),Math.end(),Comp);sort(E.begin(),E.end(),Comp);int pa,pc,pm,pe;//平均分和各科排名while(M--){cin>>student_id;for(it=s.begin();it!=s.end();it++){if((*it).Student_ID==student_id){for(i=0;i<Average.size();i++){if((*it).C+(*it).M+(*it).E==Average[i]){pa=i;//平均分排名break;}}for(i=0;i<C.size();i++){if((*it).C==C[i]){pc=i;//C语言排名break;}}for(i=0;i<Math.size();i++){if((*it).M==Math[i]){pm=i;//Math排名break;}}for(i=0;i<E.size();i++){if((*it).E==E[i]){pe=i;//English排名break;}}if((pa<=pc) && (pa<=pm) && (pa<=pe)){//找出最前排名并考虑优先性cout<<pa+1<<" A"<<endl;break;}else if((pc<pa) && (pc<=pm) && (pc<=pe)){cout<<pc+1<<" C"<<endl;break;}else if((pm<pa) && (pm<pc) && (pm<=pe)){cout<<pm+1<<" M"<<endl;break;}else{cout<<pe+1<<" E"<<endl;break;}}}if(it==s.end())cout<<"N/A"<<endl;}return 0;}



0 0
原创粉丝点击