#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int Maxn = 2020;
typedef struct record
{
int id;
int grade[4];
};
int n,m,now=0; //now全部变量利于循环在cmp函数中比较
record stu[Maxn];
int ranklist[1000000][4] = {0}; //设置数组来记录排名
char sub[4] = {'A','C','M','E'}; //用数字来对应科目
bool cmp(record a,record b)
{
return a.grade[now] > b.grade[now];
}
int main()
{
freopen("1.txt","r",stdin);
scanf("%d %d",&n,&m);
for(int i = 0;i<n;i++)
{
cin>>stu[i].id>>stu[i].grade[1]>>stu[i].grade[2]>>stu[i].grade[3];
stu[i].grade[0] = stu[i].grade[1] + stu[i].grade[2] + stu[i].grade[3]; //总值代替平均
}
for(now = 0;now<4;now++)
{
sort(stu,stu+n,cmp); //对当前科目排名
ranklist[stu[0].id][now] = 1;
for(int i = 1;i<n;i++)
{
if(stu[i].grade[now] == stu[i-1].grade[now])
ranklist[ stu[i].id ][now] = ranklist[ stu[i-1].id ][now]; //记录排名
else
ranklist[ stu[i].id ][now] = i + 1;
}
}
int temp;
for(int i = 0;i<m;i++)
{
scanf("%d",&temp);
if(ranklist[temp][0] == 0) //为0即没有该记录
{
printf("N/A\n");
//break; //break掉后面的记录都不能查询了!!!
}
else
{
int top = 5,f = 0;
for(int j = 0;j<4;j++) //第一个寻找到就是优先度最高的
{
if(top > ranklist[temp][j])
{
top = ranklist[temp][j];
f = j;
}
}
printf("%d %c\n",top,sub[f]);
}
}
return 0;
}
1012 The Best Rank (25分)
最新推荐文章于 2022-02-20 18:49:14 发布