标签:
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 3 1234567890011 9 2 4
1 #include<stdio.h> 2 #include<math.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<algorithm> 6 using namespace std; 7 8 struct tester 9 { 10 char id[20]; 11 int location, score, final_r, local_r; 12 }a[30010]; 13 14 bool cmp(tester x, tester y) 15 { 16 if(x.score != y.score) 17 return x.score > y.score; 18 else 19 return strcmp(x.id, y.id) < 0; 20 } 21 22 int main() 23 { 24 int i, j, n, m = 0; 25 scanf("%d",&n); 26 for(i = 1; i <= n; i++) 27 { 28 int k; 29 scanf("%d", &k); 30 for(j = 0; j < k; j++) 31 { 32 scanf("%s%d", a[m].id, &a[m].score); 33 a[m].location = i; 34 m++; 35 } 36 sort(a + m - k, a + m, cmp); 37 a[m - k].local_r = 1; 38 for(j = m - k + 1; j < m; j++) 39 { 40 if(a[j].score == a[j - 1].score) 41 { 42 a[j].local_r = a[j - 1].local_r; 43 } 44 else 45 { 46 a[j].local_r = j + k - m + 1; 47 } 48 } 49 } 50 sort(a, a + m, cmp); 51 a[0].final_r = 1; 52 for(i = 1; i < m; i++) 53 { 54 if(a[i].score == a[i - 1].score) 55 { 56 a[i].final_r = a[i - 1].final_r; 57 } 58 else 59 { 60 a[i].final_r = i + 1; 61 } 62 } 63 printf("%d\n", m); 64 for(i = 0; i < m; i++) 65 { 66 printf("%s %d %d %d\n", a[i].id, a[i].final_r, a[i].location, a[i].local_r); 67 } 68 return 0; 69 }
标签:
原文地址:http://www.cnblogs.com/yomman/p/4280659.html