1025 PAT Ranking (25)

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


题目大意:给出各个考点的考生id和成绩,要求把所有考点的信心合在一起,输出考生的id,合并后的排名, 考场位置, 合并前的排名
思路:建立一个struct node保存每一个学生的id, 最终排名,局部排名,成绩以及考场。 每录入完一个考场的信息,就对其排序确定学生的局部排名。 待所有信心录入完成后,对所有的考生排名,确定名次

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<vector>
 4 #include<string>
 5 using namespace std;
 6 struct node{
 7   string id;
 8   int score, final, location, local;
 9 };
10 
11 bool cmp(node a, node b){
12   if(a.score!=b.score)return a.score>b.score;
13   return a.id < b.id;
14 }
15 int main(){
16   int n, k, i, j, sum=0;
17   cin>>n;
18   vector<node> v;
19   for(i=1; i<=n; i++){
20     cin>>k;
21     sum += k;
22     node stu;
23     stu.location=i;
24     for(j=0; j<k; j++){
25       cin>>stu.id>>stu.score;
26       v.push_back(stu);
27     }
28     sort(v.begin()+sum-k, v.begin()+sum, cmp);
29     v[sum-k].local=1;
30     for(j=1; j<k; j++){
31       if(v[sum-k+j].score==v[sum-k+j-1].score) v[sum-k+j].local=v[sum-k+j-1].local;
32       else v[sum-k+j].local=j+1;
33     }
34     
35   }
36   sort(v.begin(), v.end(), cmp);
37     v[0].final = 1;
38     cout<<v.size()<<endl;
39     cout<<v[0].id<<" "<<v[0].final<<" "<<v[0].location<<" "<<v[0].local<<endl;
40     for(i=1; i<v.size(); i++){
41       if(v[i].score==v[i-1].score) v[i].final = v[i-1].final;
42       else v[i].final = i+1;
43       cout<<v[i].id<<" "<<v[i].final<<" "<<v[i].location<<" "<<v[i].local<<endl;
44     }
45   return 0;
46 }

猜你喜欢

转载自www.cnblogs.com/mr-stn/p/9161679.html