PAT_A1025#PAT Ranking

Source:

PAT A1025 PAT Ranking

Description:

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

Keys:

  • 模拟题

Code:

 1 /*
 2 Data: 2019-07-17 18:57:55
 3 Problem: PAT_A1025#PAT Ranking
 4 AC: 18:58
 5 
 6 题目大意:
 7 排序
 8 输入:
 9 第一行给出,考场数N<=100
10 接下来N个列表
11 第一行给出,考生数K<=300
12 接下来K行,id,score
13 输出:
14 考生总数
15 id,总排名,考场号,考场名次(总排名递增+id递增)
16 */
17 #include<cstdio>
18 #include<vector>
19 #include<string>
20 #include<iostream>
21 #include<algorithm>
22 using namespace std;
23 struct node
24 {
25     string id;
26     int score;
27     int ln,lr;
28 }temp;
29 vector<node> fin;
30 
31 bool cmp(const node &a, const node &b)
32 {
33     if(a.score != b.score)
34         return a.score > b.score;
35     else
36         return a.id < b.id;
37 }
38 
39 int main()
40 {
41 #ifdef    ONLINE_JUDGE
42 #else
43     freopen("Test.txt", "r", stdin);
44 #endif
45 
46     int n,k;
47     scanf("%d", &n);
48     for(int i=1; i<=n; i++)
49     {
50         scanf("%d", &k);
51         vector<node> loc;
52         for(int j=0; j<k; j++)
53         {
54             cin >> temp.id >> temp.score;
55             temp.ln = i;
56             loc.push_back(temp);
57         }
58         sort(loc.begin(),loc.end(),cmp);
59         int r=1;
60         for(int j=0; j<k; j++)
61         {
62             if(j==0 || loc[j-1].score!=loc[j].score)
63                 r = j+1;
64             loc[j].lr = r;
65             fin.push_back(loc[j]);
66         }
67     }
68     sort(fin.begin(),fin.end(),cmp);
69     printf("%d\n", fin.size());
70     int r=1;
71     for(int i=0; i<fin.size(); i++)
72     {
73         if(i==0 || fin[i-1].score!=fin[i].score)
74             r=i+1;
75         cout << fin[i].id;
76         printf(" %d %d %d\n", r,fin[i].ln,fin[i].lr);
77     }
78 
79     return 0;
80 }

 

posted @ 2019-07-17 19:20  林東雨  阅读(165)  评论(0编辑  收藏  举报