To evaluate the performance of our first year CS majored students, we consider their grades of three courses only:c-C P Rogramming Language, M-mathematics (calculus or Linear Algrbra), and E-english. At the mean time, we encourage students by emphasizing on their best ranks – that's, among the four ranks with respect T o 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 is 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 is the since the 1st one have done the best in C programming Language, While the 2nd one in mathematics, the 3rd one in 中文版, and the last one in average.
Input
Each input file contains the one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which is the total number of students, and the NUM ber of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which are a string of 6 digits, followed by the three integer grades (in th e range of [0]) of that student in the order of C, M and E. Then there is M lines, each containing a student ID.
Output
For each of the M students, print on one line, the best rank for him/her, and the symbol of the corresponding rank, Separat Ed by a space.
The priorities of the ranking methods is ordered as A > C > M > E. Hence if there is or more ways for A Stu Dent to obtain the same best rank, and the output the one with the highest priority.
If A student is isn't 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
2 b
3 A
N/A
#include <iostream> #include <vector> #include <map> #include <algorithm>using namespace std; struct student {int id; int C; int M; int E; int A;}; BOOL Sortbyc (const student& A, const student& b) {return A.C > B.C;} BOOL Sortbym (const student& A, const student& b) {return a.m. > B.M;} BOOL Sortbye (const student& A, const student& b) {return A.E > B.E;} BOOL Sortbya (const student& A, const student& b) {return a.a > B.A;} int main () {vector<student> V; Map<int, char> Mtype; Map<int, int> Mrank; int N, m, q; cin>>n>>m; for (int i=0; i<n; i++) {struct student s; cin>>s.id>>s.c>>s.m>>s.e; S.A. = (S.C + s.m + s.e)/3; V.push_back (s); } int score =-1; int rank = 0; Sort (V.begin (), V.end (), Sortbya); for (int i=0; i<v.size (); i++) {if (V[i]. A! = score) {rank = i+1; } score = V[i]. A Mrank[v[i].id] = rank; Mtype[v[i].id] = ' A '; } score =-1; Rank = 0; Sort (V.begin (), V.end (), SORTBYC); for (int i=0; i<v.size (); i++) {if (V[i]. C! = score) {rank = i+1; } score = V[i]. C if (Mrank[v[i].id]>rank) {mrank[v[i].id] = rank; Mtype[v[i].id] = ' C '; }} score =-1; Rank = 0; Sort (V.begin (), V.end (), sortbym); for (int i=0; i<v.size (); i++) {if (V[i]. M! = score) {rank = i+1; } score = V[i]. M if (Mrank[v[i].id]>rank) {mrank[v[i].id] = rank; Mtype[v[i].id] = ' M '; }} score =-1; Rank = 0; Sort (V.begin (), V.end (), Sortbye); for (int i=0; i<v.size (); i++) {if (V[i]. E! = score) {rank = i+1; } score = V[i]. E if (Mrank[v[i].id]>rank) {mrank[v[i].id] = rank; Mtype[v[i].id] = ' E '; }} for (int i=0;i<m;i++) {cin>>q; if (Mtype.count (q)) cout<<mrank[q]<< "" <<mType[q]<<endl; else cout<< "N/a" <<endl; }}
1012. The best Rank (25)