-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path10258.cpp
More file actions
85 lines (73 loc) · 1.91 KB
/
10258.cpp
File metadata and controls
85 lines (73 loc) · 1.91 KB
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
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;
typedef struct {
int num;
int ptime;
int nsolved;
int ptry[10];
bool solved[10];
bool p;
} cont;
cont contestants[101];
void init(cont &c, int n) {
c.num = n; c.ptime = 0; c.nsolved = 0;
c.p = false;
for (int i = 0; i < 10; i++) c.ptry[i] = 0;
for (int i = 0; i < 10; i++) c.solved[i] = false;
}
void init_contestants() {
for (int i = 0; i < 101; i++) init(contestants[i], i);
}
void print(cont &c) {
if (c.p) cout << c.num << ' ' << c.nsolved << ' ' << c.ptime << endl;
}
bool compare(const cont &lhs, const cont &rhs) {
if (lhs.nsolved != rhs.nsolved) return lhs.nsolved > rhs.nsolved;
if (lhs.ptime != rhs.ptime) return lhs.ptime < rhs.ptime;
return lhs.num < rhs.num;
}
void try_problem(cont &contestant, int pnum, int time, char outcome) {
contestant.p = true;
if (contestant.solved[pnum]) return;
if (outcome == 'C') {
contestant.solved[pnum] = true, contestant.ptime += time;
contestant.ptime += contestant.ptry[pnum]; contestant.nsolved++;
} else if (outcome == 'I') {
contestant.ptry[pnum] += 20;
}
}
void parse(string &str) {
size_t pos = str.find(' ');
int ind = stoi(str.substr(0, pos));
size_t npos = str.find(' ', pos+1);
int pnum = stoi(str.substr(pos, npos-pos));
pos = str.find(' ', npos+1);
int time = stoi(str.substr(npos, pos-npos));
char outcome = str[str.size()-1];
try_problem(contestants[ind], pnum, time, outcome);
}
void psol() {
sort(begin(contestants), end(contestants), compare);
for (int i = 0; i <= 100; i++) print(contestants[i]);
}
int main() {
init_contestants();
int tc; cin >> tc;
string null, line;
getline(cin, null);
getline(cin, null);
while (getline(cin, line)) {
if (line.empty()) {
psol();
init_contestants();
cout << endl;
continue;
}
parse(line);
}
psol();
return 0;
}