-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path1141_PAT Ranking of Institutions (25).cpp
76 lines (68 loc) · 1.82 KB
/
1141_PAT Ranking of Institutions (25).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
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <vector>
using namespace std;
class Record {
public:
string univ;
void update(int select, int score) {
level[select].first += score;
level[select].second += 1;
}
int studentNum() const {
return level[0].second + level[1].second + level[2].second;
}
int weightScore() const {
return int(double(level[0].first) / 1.5
+ double(level[1].first)
+ double(level[2].first) * 1.5);
}
bool operator< (const Record &o) {
if (o.weightScore() == this->weightScore()) {
if (o.studentNum() == this->studentNum())
return this->univ < o.univ;
else return this->studentNum() < o.studentNum();
}
else return this->weightScore() > o.weightScore();
}
private:
pair<int, int> level[3]; // basic, advance, top
};
int main() {
int n, score, select, curRank;
string id, univ;
unordered_map<string, int> rankIndex;
vector<Record> rankTable;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> id >> score >> univ;
transform(univ.begin(), univ.end(), univ.begin(), ::tolower);
select = id[0] == 'B' ? 0 : (id[0] == 'A' ? 1 : 2);
if (rankIndex.find(univ) == rankIndex.end()) {
Record r = Record();
r.univ = univ;
r.update(select, score);
rankTable.push_back(r);
rankIndex[univ] = rankTable.size() - 1;
} else {
rankTable[rankIndex[univ]].update(select, score);
}
}
sort(rankTable.begin(), rankTable.end());
cout << rankTable.size() << endl;
for (int i = 0; i < rankTable.size(); i++) {
if (i == 0) {
cout << "1";
curRank = 1;
} else if (rankTable[i].weightScore() == rankTable[i - 1].weightScore())
cout << curRank;
else {
cout << i + 1;
curRank = i + 1;
}
cout << " " << rankTable[i].univ << " " << rankTable[i].weightScore() << " " << rankTable[i].studentNum() << endl;
}
return 0;
}