PAT 1012. The Best Rank

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <functional>
#include <string>
#include <queue>

using namespace std;

class Stu
{
public:
	int id;
	int G[4];//ACME
};
int term=0;
bool comp(const Stu& a,const Stu& b)
{
	return a.G[term]>b.G[term];
}

Stu students[2005];

int main()
{
	int N,M;
	scanf("%d %d",&N,&M);
	for(int i=0;i<N;i++)
	{
		scanf("%d %d %d %d",&students[i].id,&students[i].G[1],&students[i].G[2],&students[i].G[3]);
		students[i].G[0] = (students[i].G[1]+students[i].G[2]+students[i].G[3])/3;
	}
	

	int lastScore = -1;
	int lastRank = -1;
	for(term=0;term<4;term++)
	{
		sort(students,students+N,comp);
		for(int i=0;i<N;i++)
		{
			int thisScore = students[i].G[term];
			if(thisScore == lastScore)
			{
				students[i].G[term] = lastRank;
			}else
			{
				students[i].G[term] = i+1;
			}
			lastScore = thisScore;
			lastRank = students[i].G[term];
		}
	}
	for(int i=0;i<M;i++)
	{
		int id;
		scanf("%d",&id);
		Stu* stu = find_if(students,students+N,[=](const Stu& a){return a.id == id;});
		if(stu != students+N)
		{
			int* maxG = min_element(stu->G,stu->G+4);
			printf("%d ",*maxG);
			if(maxG == stu->G+0)
				printf("A");
			if(maxG == stu->G+1)
				printf("C");
			if(maxG == stu->G+2)
				printf("M");
			if(maxG == stu->G+3)
				printf("E");
			
		}else
			printf("N/A");
		printf("\n");
	}
	return 0;
}



你可能感兴趣的:(PAT 1012. The Best Rank)