PAT甲级1012 The Best Rank (25分)

#pragma warning(disable:4996)
#include
#include
#include
#include
using namespace std;

struct studentinfo
{
     
	int id;
	int grade[4];
}student[2010];

int now;

bool cmp(struct studentinfo a, struct studentinfo b)
{
     
	return a.grade[now] > b.grade[now];
}

int R[1000000][4] = {
      0 };

int main()
{
     
	int N, M;
	scanf("%d%d", &N, &M);
	char course[4] = {
     'A','C','M','E'};
	for (int i = 0; i < N; i++)
	{
     
		scanf("%d%d%d%d", &student[i].id, &student[i].grade[1], &student[i].grade[2], &student[i].grade[3]);
		student[i].grade[0] = student[i].grade[1] + student[i].grade[2] + student[i].grade[3];
	}

	for (now = 0; now < 4; now++)
	{
     
		sort(student, student + N, cmp);
		R[student[0].id][now] = 1;
		for (int i = 1; i < N; i++)
		{
     
			if (student[i].grade[now] == student[i - 1].grade[now])
			{
     
				R[student[i].id][now] = R[student[i - 1].id][now];
			}
			else
			{
     
				R[student[i].id][now] = i + 1;
			}
		}
	}
	int check;
	for (int i = 0; i < M; i++)
	{
     
		scanf("%d", &check);
		if (R[check][0] == 0)
		{
     
			printf("N/A\n");
			continue;
		}
		int temp = 0;
		for (int j = 1; j < 4; j++)
		{
     
			if (R[check][j] < R[check][temp])
			{
     
				temp = j;
			}
		}
		printf("%d %c\n",R[check][temp],course[temp] );
	}
	return 0;
}

你可能感兴趣的:(PAT)