#include <iostream>
#include <string>
#include <stack>
int main() {
using namespace std;
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
string input_str; cin >> input_str;
stack<char> cursor_left, cursor_right;
for (char& ch : input_str) { cursor_left.push(ch); }
int t; cin >> t;
while (t--) {
string cmd; cin >> cmd;
if (cmd == "L" && !cursor_left.empty()) {
//move cursor to left
cursor_right.push(cursor_left.top());
cursor_left.pop();
}
else if (cmd == "D" && !cursor_right.empty()) {
//move cursor to right
cursor_left.push(cursor_right.top());
cursor_right.pop();
}
else if (cmd == "B" && !cursor_left.empty()) {
//erase character to left;
cursor_left.pop();
}
else if (cmd == "P") {
//add character to left
char ch; cin >> ch;
cursor_left.push(ch);
}
}
while (!cursor_left.empty()) {
cursor_right.push(cursor_left.top());
cursor_left.pop();
}
while (!cursor_right.empty()) {
cout << cursor_right.top();
cursor_right.pop();
}
return 0;
}
'Problem set' 카테고리의 다른 글
[백준] 1676: 팩토리얼 0의 개수 (0) | 2020.12.29 |
---|---|
[백준] 1463: 1로 만들기 (0) | 2020.12.29 |
[백준] 1373: 2진수 8진수 (0) | 2020.12.29 |
[백준] 1212: 8진수 2진수 (0) | 2020.12.29 |
[백준] 1158: 요세푸스 문제 (0) | 2020.12.29 |