#include<bits/stdc++.h>
using namespace std;
struct Grade{
char pro;
int score;
int rank;
};
struct Stu{
int id;
Grade grade[4];
};
vector<Stu> v;
map<char,int> ma;
map<int,int> m2;
int cmp1(Stu stu1,Stu stu2)
{
return stu1.grade[0].score>stu2.grade[0].score;
}
int cmp2(Stu stu1,Stu stu2)
{
return stu1.grade[1].score>stu2.grade[1].score;
}
int cmp3(Stu stu1,Stu stu2)
{
return stu1.grade[2].score>stu2.grade[2].score;
}
int cmp4(Stu stu1,Stu stu2)
{
return stu1.grade[3].score>stu2.grade[3].score;
}
int cmp5(Grade g1,Grade g2)
{
if(g1.rank!=g2.rank)
return g1.rank<g2.rank;
else
return ma[g1.pro]<ma[g2.pro];
}
int main()
{
int n,m;
scanf("%d %d",&n,&m);
Stu student;
ma['A']=1;
ma['C']=2;
ma['M']=3;
ma['E']=4;
student.grade[0].pro='C';
student.grade[1].pro='M';
student.grade[2].pro='E';
student.grade[3].pro='A';
for(int i=0;i<n;i++)
{
scanf("%d %d %d %d",&student.id,&student.grade[0].score,&student.grade[1].score,&student.grade[2].score);
m2[student.id]=1;
student.grade[3].score=(student.grade[0].score+student.grade[1].score+student.grade[2].score)/3;
v.push_back(student);
}
sort(v.begin(),v.end(),cmp1);
v[0].grade[0].rank=1;
for(int i=1;i<v.size();i++)
{
if(v[i].grade[0].score==v[i-1].grade[0].score)
{
v[i].grade[0].rank=v[i-1].grade[0].rank;
}
else
{
v[i].grade[0].rank=i+1;
}
}
sort(v.begin(),v.end(),cmp2);
v[0].grade[1].rank=1;
for(int i=1;i<v.size();i++)
{
if(v[i].grade[1].score==v[i-1].grade[1].score)
{
v[i].grade[1].rank=v[i-1].grade[1].rank;
}
else
{
v[i].grade[1].rank=i+1;
}
}
sort(v.begin(),v.end(),cmp3);
v[0].grade[2].rank=1;
for(int i=1;i<v.size();i++)
{
if(v[i].grade[2].score==v[i-1].grade[2].score)
{
v[i].grade[2].rank=v[i-1].grade[2].rank;
}
else
{
v[i].grade[2].rank=i+1;
}
}
sort(v.begin(),v.end(),cmp4);
v[0].grade[3].rank=1;
for(int i=1;i<v.size();i++)
{
if(v[i].grade[3].score==v[i-1].grade[3].score)
{
v[i].grade[3].rank=v[i-1].grade[3].rank;
}
else
{
v[i].grade[3].rank=i+1;
}
}
int id;
for(int i=0;i<m;i++)
{
scanf("%d",&id);
if(m2[id]!=1)
{
cout<<"N/A"<<endl;
}
else
{
for(int j=0;j<v.size();j++)
{
if(v[j].id==id)
{
sort(v[j].grade,v[j].grade+4,cmp5);
printf("%d %c\n",v[j].grade[0].rank,v[j].grade[0].pro);
break;
}
}
}
}
return 0;
}
1012 The Best Rank
最新推荐文章于 2022-08-16 11:09:37 发布