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 85Sample 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 31234567890011 9 2 4
/* * 1.考察结构体2级排序。。 2.求小组内部排序的时候 用no表示小组号 rank1[no]表示小组内排名 grade[no]记录no小组的成绩 num[no]记录重复成绩的 个数 因为这样方便通过student[i].room找到对应的小组 并求小组内的排名 */ #include "iostream" #include "algorithm" #include "cstring" using namespace std; int total; struct Student{ char id[14]; int room; int grade; }stu[30001]; bool cmp(Student s1,Student s2) { if (s1.grade < s2.grade) { return 0; } else if (s1.grade == s2.grade) { if (strcmp(s1.id, s2.id)<0) return 1; else return 0; } else { return 1; } } int main() { int n; int grade[101], rank1[101], num[101]; cin >> n; total = 0; int cnt = 0; for (int i = 1; i <= n; i++) { int t; int j = 0; cin >> t; while (t--) { cin >> stu[cnt].id >> stu[cnt].grade; stu[cnt++].room = i; } } cout << cnt << endl; sort(stu,stu+cnt,cmp); int rank, t; rank = 1; t = 0; memset(grade, 0, sizeof(grade)); for (int i = 0; i < 101; i++) rank1[i] = 1; memset(num, 0, sizeof(num)); for (int i = 0; i < cnt; i++) { if (grade[stu[i].room] != stu[i].grade) { /* 求小组内的排名 */ rank1[stu[i].room] += num[stu[i].room]; num[stu[i].room] = 1; grade[stu[i].room] = stu[i].grade; } else { num[stu[i].room]++; } cout << stu[i].id << " "; cout << rank <<" "; t++; cout << stu[i].room << " "; cout << rank1[stu[i].room]; if (stu[i].grade != stu[i + 1].grade && i!=cnt-1) { rank += t; t = 0; } cout << endl; } return 0; }
本文介绍了一个用于合并多个地点编程能力测试(PAT)排名的算法。该算法需要处理来自不同测试地点的输入数据,并生成最终的综合排名。文章详细解释了如何实现结构体的二级排序,以及如何计算每个参赛者的最终排名。
282

被折叠的 条评论
为什么被折叠?



