PAT 1012
#include <iostream>
#include <algorithm>
#include <string>
#define MAX_NUM 0x7fffffff 

using namespace std;

struct node
{
	string num;
	int score[4];
	int bestRank;
	int bestCourse;
};

char map[4] = { 'C', 'M', 'E', 'A' };

int main()
{
	int N, M, sum;
	cin >> N >> M;
	//node *p = (node*)malloc(N*sizeof(node));
	node *p =  new node[N];


	for (int i = 0; i < N; ++i)
	{
		string num;
		cin >> num;
		p[i].num = num;
		sum = 0;
		for (int j = 0; j < 3; ++j)
		{
			cin >> p[i].score[j];
			sum += p[i].score[j];
		}
		p[i].score[3] = sum / 3;
	}


	for (int i = 0; i < N; ++i)
	{
		int rank[4] = { N, N, N, N };

		for (int j = 0; j < N; ++j)
		{
			for (int k = 0; k < 4; ++k)
			{
				if (i != j && p[i].score[k] >= p[j].score[k])
				{
					--rank[k];
				}
			}		
		}

		int best_rank = MAX_NUM;
		int best_course = MAX_NUM;

		for (int j = 0; j < 4; ++j)
		{
			if (rank[j] < best_rank)
			{
				best_rank = rank[j];
				best_course = j;
			}
			else if (rank[j] == best_rank)
			{
				if (j == 3 || j < best_course)
				{
					best_course = j;
				}
			}
		}
		p[i].bestRank = best_rank;
		p[i].bestCourse = best_course;
	}

	for (int i = 0; i < M; ++i)
	{
		string str;
		cin >> str;
		int j;
		for (j = 0; j < N; ++j)
		{
			if (p[j].num == str)
			{
				cout << p[j].bestRank << ' ' << map[p[j].bestCourse] << endl;
				break;
			}
		}
		if (j == N)
			cout << "N/A" << endl;
	}
	
	return 0;

}

阅读更多
个人分类: PAT
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

PAT 1012

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭