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
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备注:注意排名规则,如有三个成绩90 90 88,那么排名应该是 1 1 3,而不是1 1 2。开始就死在这上面了 好像题目里也没交待清楚啊
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define MAXNUM 2010
string id[MAXNUM];
string concerned_id[MAXNUM];
int C_score[MAXNUM];
int M_score[MAXNUM];
int E_score[MAXNUM];
int A_score[MAXNUM];
int C_rank[MAXNUM];
int M_rank[MAXNUM];
int E_rank[MAXNUM];
int A_rank[MAXNUM];
void Sort_score(int A[],int size,int rank[])
{
/*用count sorting的方法,key值在A中的index放进a[key]对应的行里*/
vector<vector<int>> a(101);
int i,j;
int r;
/*count sorting*/
for(i=0;i<size;i++)
a.at(A[i]).push_back(i);
/*store the rank of index j in rank[]*/
r = 1;
for(i=100;i>=0;i--)
{
vector<int> b_v = a[i];
if(b_v.size()>0)
{
for(j=0;j<b_v.size();j++)
rank[b_v[j]] = r;
//注意排名规则:当前排名为1,有2个人排名都为1,则下一个人的排名为3;
r = r+b_v.size();
}
}
}
int main()
{
char course[]={'A','C','M','E'};
int N,M;
int i,j;
int best_rank,course_index;
string s_id;
cin>>N>>M;
for(i=0;i<N;i++)
{
cin>>id[i]>>C_score[i]>>M_score[i]>>E_score[i];
A_score[i] = (C_score[i]+M_score[i]+E_score[i])/3;
}
for(i=0;i<M;i++)
cin>>concerned_id[i];
/*sorting the grades*/
Sort_score(C_score, N, C_rank);
Sort_score(M_score, N, M_rank);
Sort_score(E_score, N, E_rank);
Sort_score(A_score, N, A_rank);
/*output the rank of M concerned students*/
for(i=0;i<M;i++)
{
best_rank = 9999;
course_index = 0;
s_id = concerned_id[i];
for(j=0;j<N;j++)
{
if(id[j]==s_id)
{
if(A_rank[j]<best_rank)
{
best_rank = A_rank[j];
course_index = 0;
}
if(C_rank[j]<best_rank)
{
best_rank = C_rank[j];
course_index = 1;
}
if(M_rank[j]<best_rank)
{
best_rank = M_rank[j];
course_index = 2;
}
if(E_rank[j]<best_rank)
{
best_rank = E_rank[j];
course_index = 3;
}
if(i==M-1)
cout<<best_rank<<" "<<course[course_index];
else
cout<<best_rank<<" "<<course[course_index]<<endl;
break;
}
}
if(j==N) //未找到id
{
if(i==M-1)
cout<<"N/A";
else
cout<<"N/A"<<endl;
}
}
return 0;
}