PAT甲级——A1025 PAT Ranking
Posted zzw1024
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT甲级——A1025 PAT Ranking相关的知识,希望对你有一定的参考价值。
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 (≤), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤), 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
简单的排序题,使用结构体
1 #include <iostream> 2 #include <vector> 3 #include <string> 4 #include <algorithm> 5 using namespace std; 6 struct Node 7 8 string No; 9 int score, final_rank, location_num, local_rank; 10 ; 11 12 bool cmp(Node* a, Node* b) 13 14 return (a->score == b->score) ? (a->No < b->No) : (a->score > b->score); 15 16 int N, K; 17 vector<Node*>allPerson; 18 int main() 19 20 cin >> N; 21 for (int i = 1; i <= N; ++i) 22 23 cin >> K; 24 vector<Node*>temp; 25 for (int j = 0; j < K; ++j) 26 27 Node* node = new Node; 28 cin >> node->No >> node->score; 29 node->location_num = i; 30 temp.push_back(node); 31 32 sort(temp.begin(), temp.end(), cmp); 33 for (int j = 0; j < temp.size(); ++j) 34 35 if (j > 0 && temp[j]->score == temp[j - 1]->score) 36 temp[j]->local_rank = temp[j - 1]->local_rank; 37 else 38 temp[j]->local_rank = j + 1; 39 40 allPerson.insert(allPerson.end(), temp.begin(), temp.end()); 41 42 sort(allPerson.begin(), allPerson.end(), cmp); 43 cout << allPerson.size() << endl; 44 for (int j = 0; j < allPerson.size(); ++j) 45 46 if (j>0 && allPerson[j]->score == allPerson[j - 1]->score) 47 allPerson[j]->final_rank = allPerson[j - 1]->final_rank; 48 else 49 allPerson[j]->final_rank = j + 1; 50 cout << allPerson[j]->No << " " << allPerson[j]->final_rank << " " << 51 allPerson[j]->location_num << " " << allPerson[j]->local_rank << endl; 52 53 return 0; 54
以上是关于PAT甲级——A1025 PAT Ranking的主要内容,如果未能解决你的问题,请参考以下文章