1025 PAT Ranking (25 分)

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

Input Specification:
Each input file contains one test case. For each case, the first line contains a positive number N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

Output Specification:
For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

registration_number final_rank location_number local_rank
The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

Sample Input:
2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
Sample Output:
9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4
**
思路:首先对每一个分考场进行排序,然后搞一个总考场容器,合并所有分考场,再进一步排序
坑点:相同分数,要根据ID升序输出
知识点:
动态申请vector容器内存,vector *classroom = new vector[N](记得delete);
**

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
class Student
{
public:
	string registration_number;
	int score;
	int final_rank;//综合排名
	int location_number;//属于第几轮
	int local_rank;//本考场排名
};
bool sort_std(Student a, Student b)
{
	return a.score > b.score;//按照成绩排序
}
bool sort_bigstd(Student a, Student b)
{
	if (a.score == b.score)
	{
		return a.registration_number < b.registration_number;//按注册号来排
	}
	return a.score > b.score;//按照成绩排序
}
int main()
{
	int N, K;
	cin >> N;//考场数
	vector<Student> *classroom = new vector<Student>[N];//动态申请N块内存
	vector<Student>BigClassroom;
	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> K;
		sum += K;
		for (int j = 0; j < K; j++)
		{
			Student std;
			cin >>std.registration_number>>std.score;
			std.location_number = i + 1;
			classroom[i].push_back(std);
		}
		sort(classroom[i].begin(), classroom[i].end(), sort_std);
		int k = 1;
		for (auto &i : classroom[i])
		{
			i.local_rank = k;
			k++;
		}
		for (int j = 1; j < K; j++)
		{
			if (classroom[i][j].score == classroom[i][j - 1].score)
			{
				classroom[i][j].local_rank = classroom[i][j - 1].local_rank;
			}
		}
		BigClassroom.insert(BigClassroom.end(), classroom[i].begin(), classroom[i].end());
		//分考场并入最终大考场
	}
	sort(BigClassroom.begin(), BigClassroom.end(), sort_bigstd);
	int k = 1;
	for (auto &i : BigClassroom)
	{
		i.final_rank = k;
		k++;
	}
	for (int i = 1; i < BigClassroom.size(); i++)
	{
		if (BigClassroom[i].score == BigClassroom[i - 1].score)
		{
			BigClassroom[i].final_rank = BigClassroom[i - 1].final_rank;
		}
	}
	cout << sum << endl;
	for (auto k: BigClassroom)
	{
		cout << k.registration_number << " " << k.final_rank <<
			" " << k.location_number << " " << k.local_rank << endl;
	}
	delete []classroom;
}

你可能感兴趣的:(1025 PAT Ranking (25 分))