-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path649.cpp
More file actions
40 lines (38 loc) · 1.05 KB
/
649.cpp
File metadata and controls
40 lines (38 loc) · 1.05 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
class Solution {
public:
string predictPartyVictory(string senate) {
// Prepare queues.
queue<int> R;
queue<int> D;
for (size_t i = 0; i < senate.size(); i++) {
if (senate[i] == 'R') {
R.push(i);
}
// senator is D.
else {
D.push(i);
}
}
// Simulate.
int r, d;
while (1) {
if (R.empty()) {
return "Dire";
}
else if (D.empty()) {
return "Radiant";
}
r = R.front(); R.pop();
d = D.front(); D.pop();
// ban D ; reschedule R
if (r < d) {
R.push(r + senate.size());
}
// ban R ; reschedule D
else {
D.push(d + senate.size());
}
}
return "failed";
}
};