1025. PAT Ranking (25)

1025. PAT Ranking (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;


struct stu{
	string num;//注册号
	int score;//得分
	int rank;//总排名
	int local_rank;//本地排名
	int loc;//考点
};
stu all[30001];

bool cmp(stu a, stu b){
	if (a.score == b.score)//分数相同时按照注册号排序
		return a.num < b.num;
	return a.score > b.score;
}

int main(){
	int n, k;
	stu temp[301];
	int total = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> k;
		for (int j = 0; j < k; j++){
			cin >> temp[j].num >> temp[j].score;
			temp[j].loc = i + 1;
		}
		sort(&temp[0], &temp[k], cmp);//先在本地进行排名
		for (int j = 0; j < k; j++){
			temp[j].local_rank = j + 1;//得出本地的排名
			if (j >0 && temp[j].score == temp[j - 1].score)//和前一个人分数相同,则排名并列
				temp[j].local_rank = temp[j - 1].local_rank;
			all[total++] = temp[j];//放入总数据库
		}
	}
	sort(&all[0], &all[total], cmp);//所有人排名
	for (int i = 0; i < total; i++){
		all[i].rank = i + 1;
		if (i >0 && all[i].score == all[i - 1].score)//分数相同,,总排名并列
			all[i].rank = all[i - 1].rank;
	}
	cout << total << endl;//总人数

	for (int i = 0; i < total; i++){
		cout << all[i].num << " "<< all[i].rank << " "<< all[i].loc << " "<< all[i].local_rank << endl;
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章