-
Notifications
You must be signed in to change notification settings - Fork 0
/
1025.cpp
118 lines (103 loc) · 2.49 KB
/
1025.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
struct Score
{
int location; //考试地点编号 1~N
string registration; // 注册号
int score; //成绩
int final_rank = 0;
int local_rank = 0;
};
bool localSort(const Score& t1, const Score& t2)
{
return t1.score > t2.score;
}
bool finalSort(const Score& t1, const Score& t2)
{
if (t1.score != t2.score)
return t1.score > t2.score;
else
return t1.registration < t2.registration;
}
int main()
{
int N; // 考场数
scanf("%d", &N);
vector<vector<Score>> testees(N);
Score temp;
/* 数据录入 */
for (int i = 0; i < N; i++)
{
int K; //该考场考生数
scanf("%d", &K);
for (int j = 0; j < K; j++)
{
cin >> temp.registration;
cin >> temp.score;
temp.location = i + 1; //编号从1开始
testees[i].push_back(temp);
}
}
/* 局部排名 */
int start = 0;
for (int i = 0; i < N; i++)
{
//依据成绩从大到小排列
sort(testees[i].begin(), testees[i].end(), localSort);
int rank = 0;
int lastScore = 1000000;
int count = 0;
for (int j = 0; j < testees[i].size(); j++)
{
if (testees[i][j].score != lastScore) // 和上一个人成绩不同
{
rank = rank + count + 1;
testees[i][j].local_rank = rank;
lastScore = testees[i][j].score;
count = 0; //累计数清零
}
else // 和上一个人成绩相同
{
count++;
testees[i][j].local_rank = rank;
}
}
}
/* 最终排名 */
vector<Score> totalTestee;
for (int i = 0; i < N; i++)
{
totalTestee.insert(totalTestee.end(), testees[i].begin(), testees[i].end());
}
//依据成绩从大到小排列
sort(totalTestee.begin(), totalTestee.end(), finalSort);
int rank = 0;
int lastScore = 1000000;
int count = 0;
for (int i = 0; i < totalTestee.size(); i++)
{
if (totalTestee[i].score != lastScore) // 和上一个人成绩不同
{
rank = rank + count + 1;
totalTestee[i].final_rank = rank;
lastScore = totalTestee[i].score;
count = 0; //累计数清零
}
else // 和上一个人成绩相同
{
count++;
totalTestee[i].final_rank = rank;
}
//cout <<"score = " << totalTestee[i].score << " rank = " << rank << " count = " << count << endl;
}
cout << totalTestee.size() << endl;
for (int i = 0; i < totalTestee.size(); i++)
{
cout << totalTestee[i].registration << " " << totalTestee[i].final_rank << " " << totalTestee[i].location << " " << totalTestee[i].local_rank << endl;
}
return 0;
}