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 Input5 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 999999Sample Output
1 C 1 M 1 E 1 A 3 A N/A
#include<iostream> #include<algorithm> using namespace std; struct Student { int studentID; int score_C; int score_M; int score_E; int score_A; int num; }stu[2002]; //保存学生C,M,E,A这4个的排名 int map[2002][4]; char c[4] = {'C', 'M', 'E', 'A'}; //自定义cmp()函数 bool cmp_C(Student s1, Student s2) { return s1.score_C > s2.score_C; } bool cmp_M(Student s1, Student s2) { return s1.score_M > s2.score_M; } bool cmp_E(Student s1, Student s2) { return s1.score_E > s2.score_E; } bool cmp_A(Student s1, Student s2) { return s1.score_A > s2.score_A; } int main() { int n, m; while(cin>>n>>m) { for(int i = 0; i < n; i ++) { cin>>stu[i].studentID>>stu[i].score_C>>stu[i].score_M>>stu[i].score_E; stu[i].score_A = (stu[i].score_C+stu[i].score_M+stu[i].score_E) / 3; stu[i].num = i; } //按C Programming Language从高到低进行排序 sort(stu, stu+n, cmp_C); map[stu[0].num][0] = 1; for(int i = 1; i < n; i ++) { //如果分数相同,则和前面的同学的排名相同 if(stu[i].score_C == stu[i-1].score_C) { map[stu[i].num][0] = map[stu[i-1].num][0]; } else { map[stu[i].num][0] = i + 1; } } //按Mathematics从高到低进行排序 sort(stu, stu+n, cmp_M); map[stu[0].num][1] = 1; for(int i = 1; i < n; i ++) { //如果分数相同,则和前面的同学的排名相同 if(stu[i].score_M == stu[i-1].score_M) { map[stu[i].num][1] = map[stu[i-1].num][1]; } else { map[stu[i].num][1] = i + 1; } } //按English从高到低进行排序 sort(stu, stu+n, cmp_E); map[stu[0].num][2] = 1; for(int i = 1; i < n; i ++) { //如果分数相同,则和前面的同学的排名相同 if(stu[i].score_E == stu[i-1].score_E) { map[stu[i].num][2] = map[stu[i-1].num][2]; } else { map[stu[i].num][2] = i + 1; } } //按Average从高到低进行排序 sort(stu, stu+n, cmp_A); map[stu[0].num][3] = 1; for(int i = 1; i < n; i ++) { //如果分数相同,则和前面的同学的排名相同 if(stu[i].score_A == stu[i-1].score_A) { map[stu[i].num][3] = map[stu[i-1].num][3]; } else { map[stu[i].num][3] = i + 1; } } bool flag; int ID; for(int i = 0; i < m; i ++) { cin>>ID; //是否存在对应studentID的学生 flag = false; for(int j = 0; j < n; j ++) { if(stu[j].studentID == ID) { int order = stu[j].num; //如果Average排名最好 if(map[order][3] <= map[order][0] && map[order][3] <= map[order][1] && map[order][3] <= map[order][2]) { cout<<map[order][3]<<" "<<c[3]<<endl; flag = true; break; } //如果C Programming Language排名最好 else if(map[order][0] <= map[order][1] && map[order][0] <= map[order][2]) { cout<<map[order][0]<<" "<<c[0]<<endl; flag = true; break; } //如果Mathematics排名最好 else if(map[order][1] <= map[order][2]) { cout<<map[order][1]<<" "<<c[1]<<endl; flag = true; break; } //如果English排名最好 else { cout<<map[order][2]<<" "<<c[2]<<endl; flag = true; break; } } } //改studentID不存在,则输出N/A if(flag == false) cout<<"N/A"<<endl; } } return 0; }