1012 The Best Rank (25 分)
思路
多组排序,按照指定全局变量进行compare函数的设置,比较获得rank
代码
#include <bits/stdc++.h>
using namespace std;
struct stu{
int id;
int C[4];
int c1[4];
}stud[2005];
int number = 0;
bool cmp1(stu a,stu b)
{
return a.C[number] > b.C[number];
}
int main()
{
char ch[4] = {'A','C','M','E'};
int n,m;
cin>>n>>m;
int in_id, a,b,c,num=0;
for(int i=0;i<n;i++)
{
cin>>in_id>>a>>b>>c;
stud[num].id = in_id;
stud[num].C[0] = (a+b+c)/3;
stud[num].C[1] = a;
stud[num].C[2] = b;
stud[num++].C[3] = c;
}
int point , rank ;
for (int j=0;j<4;j++)
{
number = j;
sort(stud,stud+num,cmp1);
stud[0].c1[j] = 1;
for(int i=1;i<n;i++)
{
if(stud[i].C[j] == stud[i-1].C[j] )
stud[i].c1[j] = stud[i-1].c1[j];
else
stud[i].c1[j] = i+1;
}
}
for(int i=0;i<m;i++)
{
int flag = 0;
cin>>in_id;
for(int j=0;j<n;j++)
{
if(in_id == stud[j].id)
{
int pp = 0;
for(int k =1;k<4;k++)
{
if(stud[j].c1[k]<stud[j].c1[pp])
pp = k;
}
cout<<stud[j].c1[pp]<<' '<<ch[pp]<<endl;
flag = 1;
break;
}
}
if(flag)continue;
else
cout<<"N/A"<<endl;
}
}