原题目:
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 NNN and MMM (≤2000\le 2000≤2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then NNN 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 MMM lines, each containing a student ID.
Output Specification:
For each of the MMM 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
源代码:
#include<iostream>
#include<algorithm>
using namespace std;
struct Student{
int id;
int cl;
int math;
int eng;
int ave;
};
bool cmp1(Student s1, Student s2){
return s1.cl > s2.cl;
}
bool cmp2(Student s1, Student s2){
return s1.math > s2.math;
}
bool cmp3(Student s1, Student s2){
return s1.eng > s2.eng;
}
bool cmp4(Student s1, Student s2){
return s1.ave > s2.ave;
}
int main(){
int n, m;
cin>>n>>m;
char c[4] = {'C', 'M', 'E', 'A'};
int wc[m];
int sortnum[m];
char sortclass[m];
Student stu[n];
for(int i = 0; i < n; i ++){
cin>>stu[i].id>>stu[i].cl>>stu[i].math>>stu[i].eng;
stu[i].ave = (stu[i].cl + stu[i].math + stu[i].eng);
}
for(int i = 0; i < m; i ++){
cin>>wc[i];
int minnum = n + 1;
int minclass = -1;
sort(stu, stu + n, cmp4);
for(int j = 0; j < n; j ++){
if(stu[j].id == wc[i]){
int tmp = 0;
for(int k = j - 1; k >= 0; k --)
if(stu[j].ave == stu[k].ave)
tmp ++;
else
break;
if(j - tmp < minnum){
minnum = j - tmp;
minclass = 3;
break;
}
}
}
sort(stu, stu + n, cmp1);
for(int j = 0; j < n; j ++){
if(stu[j].id == wc[i]){
int tmp = 0;
for(int k = j - 1; k >= 0; k --)
if(stu[j].cl == stu[k].cl)
tmp ++;
else
break;
if(j - tmp < minnum){
minnum = j - tmp;
minclass = 0;
break;
}
}
}
sort(stu, stu + n, cmp2);
for(int j = 0; j < n; j ++){
if(stu[j].id == wc[i]){
int tmp = 0;
for(int k = j - 1; k >= 0; k --)
if(stu[j].math == stu[k].math)
tmp ++;
else
break;
if(j - tmp < minnum){
minnum = j - tmp;
minclass = 1;
break;
}
}
}
sort(stu, stu + n, cmp3);
for(int j = 0; j < n; j ++){
if(stu[j].id == wc[i]){
int tmp = 0;
for(int k = j - 1; k >= 0; k --)
if(stu[j].eng == stu[k].eng)
tmp ++;
else
break;
if(j - tmp < minnum){
minnum = j - tmp;
minclass = 2;
break;
}
}
}
if(minclass == -1){
cout<<"N/A"<<endl;
continue;
}
cout<<minnum + 1<<" "<<c[minclass]<<endl;
}
}
已AC:
易失分点:
1.注意相同排名下不同科目的优先级
2.如果两人分数相同,他们的名称也应该相同,但是后一名应该是他们的名词+2,而不是+1.