题目
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 Algrbra), 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 Specification:
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 Specification:
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
题目大意
为了评估一年级计算机科学专业学生的成绩,我们只考虑他们三门课程的成绩:C-C编程语言、M-Mathematics(微积分或线性代数)和E-English。同时,我们通过强调学生的最佳等级来鼓励学生,也就是说,在三门课程和平均成绩的四个等级中,我们为每个学生打印出最佳等级。
例如,C、M、E和平均4名学生的成绩如下:
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91
所有学生的最佳排名都是第一,因为第一名的C语言成绩最好,第二名的数学成绩最好,第三名的英语成绩最好,最后一名的平均成绩最好。
输入规格:
每个输入文件包含一个测试用例。每一个案例都以一行开始,其中包含2个数字N和M(≤2000),这两个数字分别是学生总数和将检查其排名的学生人数。接下来是N行,每行包含一个学生ID,它是一个由6位数字组成的字符串,后面是该学生的三个整数等级(在[0,100]范围内),顺序是C,M和E。然后是M行,每行包含一个学生ID。
输出规格:
对于M个学生中的每一个,在一行中打印出他/她的最佳等级,以及相应等级的符号,用空格隔开。
排序方法的优先级顺序为A>C>M>E。因此,如果一个学生有两种或两种以上的方式获得相同的最佳排名,则输出优先级最高的一种。
如果学生不在评分表上,只需输出N/a。
样本输入:
5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
样本输出:
1 C
1 M
1 E
1 A
3 A
N/A
思路分析
先用结构体存储每个student的信息,外加一个rank.然后进行a,c,m,e的四个不同优先性的排序(写四个cmp函数即可实现)。第一个排序以后,定基准,map实现(提升效率)。再进行第2,3,4次排序,如果排名比第一次排序高,进行更新。最后输出map。
测试点分析
题目类型:排序
测试点 0和4:常规测试点,只要将标准测试案例通过,这两个测试点案例也能通过。
测试点 1,2,3:卡的是,在分数相同的情况下,排名也要相同。
代码
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
struct node
{
string id;
int c, m, e, a;
int rank;
}tmp;
struct node2
{
int rank;
char course;
};
map<string