-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcongaline.cpp
More file actions
80 lines (71 loc) · 2.09 KB
/
congaline.cpp
File metadata and controls
80 lines (71 loc) · 2.09 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
//A0237056E
//Leo Zheng Rui, Darren
//LAB 09
//Cai Jia Lin
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
int N, Q; cin >> N >> Q;
unordered_map<string, list<string>::iterator> couples;
list<string> conga;
list<string>::iterator mic;
while (N--) {
string first;
string second;
cin >> first >> second;
conga.push_back(first);
conga.push_back(second);
auto mic = conga.end();
couples[first] = --mic;
couples[second] = --mic;
}
mic = conga.begin();
while (Q--) {
char token;
cin >> token;
if (token == 'F') {
--mic;
} else if (token == 'B') {
++mic;
} else if (token == 'R') {
if (mic == --conga.end()) {
mic = conga.begin();
} else {
auto m = mic;
auto n = mic;
++mic;
conga.push_back(*m);
conga.erase(n);
couples[*couples[*m]] = --conga.end();
}
} else if (token == 'C') {
auto m = mic;
auto n = mic;
auto pos = couples[*m];
if (mic == --conga.end()) {
mic = conga.begin();
conga.insert (++pos, *m);
couples[*couples[*m]] = --pos;
conga.erase(n);
} else {
++mic;
if (pos != --conga.end()) {
conga.insert (++pos, *m);
couples[*couples[*m]] = --pos;
conga.erase(n);
} else {
conga.push_back(*m);
conga.erase(n);
couples[*couples[*m]] = --conga.end();
}
}
} else if (token == 'P') {
cout << *couples[*mic] << '\n';
}
}
for (auto const &c : conga) {
cout << '\n' << c;
}
return 0;
}