Note
- 排序
- 全局变量的设置!!!
int w=-1;
bool compare(student a,student b){
if(w!=-1) return a.grade[w]>b.grade[w];
}
-
注意排序后序号会发生改变!!!需要重新写yes数组!!!
-
注意有相同分数时的排名:
e.g. (90 90 88 87 86) 排名应该是 1 1 3 4 5(不是1 2 3 4 5)
if(stu[j].grade[w]==stu[j-1].grade[w])
stu[j].rank[w]=stu[j-1].rank[w];
else
stu[j].rank[w]=j+1;
Code:
#include<bits/stdc++.h>
using namespace std;
struct student{
int grade[4];
int rank[4];
int id,best;
student(){
//memset(rank,1,sizeof(rank));
for(int i=0;i<4;i++) rank[i]=1;
}
};
int w=-1;
bool compare(student a,student b){
if(w!=-1) return a.grade[w]>b.grade[w];
}
int yes[1000000];
int main(){
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
int n,m;
cin>>n>>m;
int id,cc,mm,ee,iid;
int min,index;
char sign[4]={'A','C','M','E'};
memset(yes,-1,sizeof(yes));
struct student stu[n];
for(int i=0;i<n;i++){
cin>>id>>cc>>mm>>ee;
stu[i].id=id;
stu[i].grade[0]=(int)((cc+mm+ee)*1.0/3+0.5); //四舍五入
stu[i].grade[1]=cc;
stu[i].grade[2]=mm;
stu[i].grade[3]=ee;
}
for(w=0;w<4;w++){
sort(stu,stu+n,compare);
stu[0].rank[w]=1;
for(int j=1;j<n;j++){
if(stu[j].grade[w]==stu[j-1].grade[w]){
stu[j].rank[w]=stu[j-1].rank[w];
}
else{
stu[j].rank[w]=j+1;
}
}
}
for(int i=0;i<n;i++){
yes[stu[i].id]=i;
int min=100000;
for(int j=0;j<4;j++){
if(min>stu[i].rank[j]){
min=stu[i].rank[j];
stu[i].best=j;
}
}
}
while(m--){
cin>>iid;
if(yes[iid]==-1) cout<<"N/A\n";
else{
index=stu[yes[iid]].best;
min=stu[yes[iid]].rank[index];
printf("%d %c\n",min,sign[index]);
}
}
return 0;
}