-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path1153_Decode Registration Card of PAT (25).cpp
79 lines (75 loc) · 2.55 KB
/
1153_Decode Registration Card of PAT (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
77
78
79
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct Student {
string raw;
char level;
int examRoom;
string date;
string id;
int score;
Student(string raw, int score) {
this->raw = raw;
this->level = raw[0];
this->examRoom = (raw[1]-'0')*100 + (raw[2]-'0')*10 + (raw[3]-'0');
this->date = raw.substr(4, 6);
this->id = raw.substr(10, 3);
this->score = score;
}
};
int main() {
std::ios::sync_with_stdio(false);
int n, m, command, score;
string raw, param;
cin >> n >> m;
unordered_map<char, vector<pair<string, int>>> c1;
unordered_map<int, pair<int, int>> c2;
unordered_map<string, unordered_map<int, int>> c3;
for (int i = 0; i < n; i++) {
cin >> raw >> score;
Student s = Student(raw, score);
c1[s.level].push_back({raw, score});
c2[s.examRoom].first += 1;
c2[s.examRoom].second += score;
c3[s.date][s.examRoom] += 1;
}
for (int i = 1; i <= m; i++) {
cin >> command >> param;
cout << "Case " << i << ": " << command << " " << param << endl;
if (command == 1) {
char level = param[0];
if (c1.find(level) == c1.end()) cout << "NA" << endl;
else {
sort(c1[level].begin(), c1[level].end(), [&](const auto &a, const auto &b){
if (a.second == b.second) return a.first < b.first;
else return a.second > b.second;
});
for (const auto &v : c1[level]) {
cout << v.first << " " << v.second << endl;
}
}
} else if (command == 2) {
int room = stoi(param);
if (c2.find(room) == c2.end()) cout << "NA" << endl;
else cout << c2[room].first << " " << c2[room].second << endl;
} else if (command == 3) {
if (c3.find(param) == c3.end()) cout << "NA" << endl;
else {
vector<pair<int, int>> t;
for (const auto &kv : c3[param])
t.push_back({kv.first, kv.second});
sort(t.begin(), t.end(), [&](const auto &a, const auto &b){
if (a.second == b.second) return a.first < b.first;
else return a.second > b.second;
});
for (const auto &v : t) {
cout << v.first << " " << v.second << endl;
}
}
}
}
return 0;
}