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), andE
- 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.为了评估我们第一年CS专业学生的表现,我们只考虑他们三门课程的成绩:
C
- C编程语言,M
- 数学(微积分或线性Algrbra),和E
- 英语。同时,我们鼓励学生强调他们最好的队伍 - 也就是说,在三门课程和平均成绩的四个等级中,我们为每个学生打印最佳等级。For example, The grades of
C
,M
,E
andA
- 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.
然后,所有学生的最佳排名是No.1,因为第一个在C语言编程方面做得最好,而第二个在数学方面,第三个在英语,最后一个在平均。
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
andE
. Then there are M lines, each containing a student ID.每个输入文件包含一个测试用例。每个案例都以包含2个数字的行开头N和M(≤ 2 0 0 0),这是学生总数,谁会检查他们的行列,分别为学生的数量。然后接下来是N行,每行包含一个学生ID,该学生ID是一个6位数的字符串,然后是该学生的三个整数等级(在[0,100]范围内)的顺序
C
,M
和E
。然后有M行,每行包含学生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
.排名方法的优先级按顺序排列
A
>C
>M
>E
。因此,如果学生有两种或更多种方式获得相同的最佳等级,则输出具有最高优先级的学生。如果学生不在评分列表中,只需输出即可
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
样例解释 STUDENTID C M E Average BEST 310101 stu[0].score[1]=98
min=stu[0].rank[1]=1
stu[0].best=1
stu[0].score[2]=85
stu[0].rank[2]=5
stu[0].score[3]=88
stu[0].rank[3]=4
stu[0].score[0]=90
stu[0].rank[0]=2
1 C 310102 stu[1].score[1]=70
stu[1].rank[1]=5
stu[1].score[2]=95
min=stu[1].rank[2]=1
stu[1].best=2
stu[1].score[3]=88
stu[1].rank[3]=4
stu[1].score[0]=84
stu[1].rank[0]=5
1 M 310103 stu[2].score[1]=82
stu[2].rank[1]=4
stu[2].score[2]=87
stu[2].rank[2]=4
stu[2].score[3]=94
min=stu[2].rank[3]=1
stu[2].best=3
stu[2].score[0]=88
stu[2].rank[0]=3
1 E 310104 stu[3].score[1]=91
stu[3].rank[1]=2
stu[3].score[2]=91
stu[3].rank[2]=2
stu[3].score[3]=91
stu[3].rank[3]=2
stu[3].score[0]=91
min=stu[3].rank[0]=1
stu[3].best=0
1 A 310105 stu[4].score[1]=85
stu[4].rank[1]=3
stu[4].score[2]=90
stu[4].rank[2]=3
stu[4].score[3]=90
stu[4].rank[3]=3
stu[4].score[0]=88
min=stu[4].rank[0]=3
stu[4].best=0
3 A
exist [stu[0].id==310101]= 1 exist [stu[1].id==310102]= 2 exist [stu[2].id==310103]= 3 exist [stu[3].id==310104]= 4 exist [stu[4].id==310105]= 5
查询的ID temp best stu[temp-1].rank[best] c[best] 310101 exist[310101]=1 stu[0].best=1 stu[0].rank[1]=1 C 310102 exist[310102]=2 stu[1].best=2 stu[1].rank[2]=1 M 310103 exist[310103]=3 stu[2].best=3 stu[2].rank[3]=1 E 310104 exist[310104]=4 stu[3].best=0 stu[3].rank[0]=1 A 310105 exist[310105]=5 stu[4].best=0 stu[4].rank[0]=3 A
#include<iostream>
#include<algorithm>///排序
using namespace std;
struct student
{
int id,best;///存放6位ID
int score[4],rank[4];///存放三门课对应的排名
} stu[2001];
int exist[1000000],flag;///exit用于验证是否存在
bool cmp(student a,student b)
{
return a.score[flag]>b.score[flag];
}///按flag号进行排序
int main()
{
int n,m,id;
cin>>n>>m;///n个学生,查m次
for(int i=0; i<n; i++)
{
cin>>stu[i].id>>stu[i].score[1]>>stu[i].score[2]>>stu[i].score[3];
stu[i].score[0]=(stu[i].score[1]+stu[i].score[2]+stu[i].score[3])/3+0.5;
}///每输入一次就计算平均值并且四舍五入(+0.5)
for(flag=0; flag<=3; flag++)
{
sort(stu,stu+n,cmp);///对每一门成绩及平均分进行从高到低排序
stu[0].rank[flag]=1;///排序完将最高成绩设为1
for(int i=1; i<n; i++)
{///设置其他学生的排名
if(stu[i].score[flag]==stu[i-1].score[flag])
stu[i].rank[flag]=stu[i-1].rank[flag];
///如果和后一个同学分数相同,设置排名相同
stu[i].rank[flag]=i+1;///否则就设置排名为第2,3,4....
}
}
for(int i=0; i<n; i++)
{
exist[stu[i].id]=i+1;///存放ID:exist[310101]=1,exist[310102]=2.....
int min=stu[i].rank[0];
for(int j=1; j<=3; j++)
{///对于每一行找stu[i].rank的最小值,因为最小的是最好的
if(stu[i].rank[j]<min)
{
min=stu[i].rank[j];
stu[i].best=j;
}
}
}
char c[5]= {'A','C','M','E'};
///优先级A>C>M>E,分配序号0,1,2,3
for(int i=0; i<m; i++)
{
cin>>id;///输入查询ID
int temp=exist[id];
if(temp)
{
int best=stu[temp-1].best;
cout<<stu[temp-1].rank[best]<<" "<<c[best]<<endl;
}
else///不存在
cout<<"N/A"<<endl;
}
}