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
题目大意:
为了评估我们第一学年CS专业学生的表现,我们根据他们的三门课程的成绩:C-C编程语言,M-数学(微积分或线性代数),E-英语。与此同时,我们通过强调学生的最好名次来鼓励学生,即在这三门课程和平均成绩中,我们打印出每个学生的最好排名。
例如,4个学生的C、M、E和A(平均成绩)如下:
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
然后所有学生的最好成绩都是第一名,因为第一名是C语言编程的第一名,第二名是数学,第三名是英语,最后一个是平均成绩。
输入:
每个测试文件包含一个测试用例。每一个案例第一行一两个数字N和M(<=2000)开头
,分别是学生的总数和要查询的学生排名的数量。接下来是N行,每行包括一个6位数的学生ID字符串,然后是三个整数成绩(0-100)依次是C、M和E。接下来是M行,每行是一个学生ID。
输出:
对M个学生中的每一个,打印出他/她最好的排名,以及相应的等级符号,用空格隔开。
排序方法的优先排序为A>C>M>E。因此如果一个学生有两门或者多门课有相同的排名,按优先级输出。
如果一个学生不在成绩列表中,输出“N/A”。
代码:
#include<bits/stdc++.h>
#define eps 1.e-8
struct grad
{
char id[10];
double grade_A;
int rank_A;
int grade_M;
int rank_M;
int grade_E;
int rank_E;
int grade_C;
int rank_C;
}student[3001];
int cmpM( const void *a ,const void *B)
{
return (*(grad *)a).grade_M < (*(grad *)B).grade_M ? 1 : -1;
}
int cmpE( const void *a ,const void *B)
{
return (*(grad *)a).grade_E < (*(grad *)B).grade_E ? 1 : -1;
}
int cmpC( const void *a ,const void *B)
{
return (*(grad *)a).grade_C < (*(grad *)B).grade_C ? 1 : -1;
}
int cmpA( const void *a ,const void *B)
{
return (*(grad *)a).grade_A+eps <(*(grad *)B).grade_A+eps? 1 : -1;
}
char stud_id[2001][10],c;
int main()
{
int i,j,n,m,k,t,r;
char s[10];
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%s %d %d %d",student[i].id,&student[i].grade_C,&student[i].grade_M,&student[i].grade_E);
student[i].grade_A=(student[i].grade_C+student[i].grade_M+student[i].grade_E)/3.0;
}
for(i=0;i<m;i++)
{
scanf("%s",stud_id[i]);
}
qsort(student,n,sizeof(student[0]),cmpM);
for(i=0;i<n;i++)
{
if(i==0)
{
student[i].rank_M=1;
}
else
{
if(student[i].grade_M==student[i-1].grade_M)
{
student[i].rank_M=student[i-1].rank_M;
}
else
{
student[i].rank_M=i+1;
}
}
}
qsort(student,n,sizeof(student[0]),cmpC);
for(i=0;i<n;i++)
{
if(i==0)
{
student[i].rank_C=1;
}
else
{
if(student[i].grade_C==student[i-1].grade_C)
{
student[i].rank_C=student[i-1].rank_C ;
}
else
{
student[i].rank_C=i+1;
}
}
}
qsort(student,n,sizeof(student[0]),cmpE);
for(i=0;i<n;i++)
{
if(i==0)
{
student[i].rank_E=1;
}
else
{
if(student[i].grade_E==student[i-1].grade_E)
{
student[i].rank_E=student[i-1].rank_E ;
}
else
{
student[i].rank_E=i+1;
}
}
}
qsort(student,n,sizeof(student[0]),cmpA);
for(i=0;i<n;i++)
{
if(i==0)
{
student[i].rank_A=1;
}
else
{
if(fabs(student[i].grade_A-student[i-1].grade_A)<eps)
{
student[i].rank_A=student[i-1].rank_A ;
}
else
{
student[i].rank_A=i+1;
}
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(strcmp(stud_id[i],student[j].id)==0)
{
r=student[j].rank_A;
c='A';
if(student[j].rank_C<r)
{
r=student[j].rank_C;
c='C';
}
if(student[j].rank_M<r)
{
r=student[j].rank_M;
c='M';
}
if(student[j].rank_E<r)
{
r=student[j].rank_E;
c='E';
}
if(i==m-1)
printf("%d %c",r,c);
else
printf("%d %c\n",r,c);
break;
}
}
if(j>=n)
{
if(i==m-1)
printf("N/A");
else
printf("N/A\n");
}
}
return 0;
}