forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1406.cpp
More file actions
39 lines (38 loc) · 815 Bytes
/
1406.cpp
File metadata and controls
39 lines (38 loc) · 815 Bytes
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
// Authored by : BaaaaaaaaaaarkingDog
// Co-authored by : -
// http://boj.kr/84654f16875542e6a84d3da7e4cf0dac
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
string init;
cin >> init;
list<char> L;
for (auto c : init) L.push_back(c);
auto cursor = L.end();
int q;
cin >> q;
while (q--) {
char op;
cin >> op;
if (op == 'P') {
char add;
cin >> add;
L.insert(cursor, add);
}
else if (op == 'L') {
if (cursor != L.begin()) cursor--;
}
else if (op == 'D') {
if (cursor != L.end()) cursor++;
}
else { // 'B'
if (cursor != L.begin()) {
cursor--;
cursor = L.erase(cursor);
}
}
}
for (auto c : L) cout << c;
}