https://www.patest.cn/contests/pat-a-practise/1012
使用基数排序
部分代码参考了:http://blog.csdn.net/jtjy568805874/article/details/50782867
#include <cstdio>
int wc[4][102];
int ids[1000001];
int scor[2001][4];
int rank[2001][4];
char ch[4] = { 'C','M','E','A' };
int main()
{
int n, m, x;
scanf("%d %d", &n, &m);
for (int i = 1; i <=n ; i++)
{
scanf("%d",&x); ids[x] = i;
for (int j = 0; j < 3; j++) { scanf("%d", &scor[i][j]); wc[j][scor[i][j]]++; }
scor[i][3] = (scor[i][0] + scor[i][1] + scor[i][2]) / 3;
wc[3][scor[i][3]]++;
}
for (int j = 0; j < 4; j++)
for (int i = 100; i >=0; i--)
wc[j][i] += wc[j][i + 1];
for (int i = 1; i <= n; i++)
for (int j = 0; j < 4; j++)
rank[i][j] = wc[j][scor[i][j] + 1];
for (int i = 0; i < m; i++)
{
scanf("%d", &x);
if (!ids[x]) {printf("N/A\n"); continue;}
int r = 3;
for (int j = 0; j < 4; j++) if (rank[ids[x]][j] < rank[ids[x]][r]) r = j;
printf("%d %c\n", rank[ids[x]][r] + 1, ch[r]);
}
return 0;
}