BOJ 1406 C++ 에디터
백준 1406
#include <bits/stdc++.h>
using namespace std;
int ea;
list<char> editor;
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
string line;
cin >> line;
for (int i = 0; line[i]; i++) {
editor.push_back(line[i]);
}
auto t = editor.end();
cin >> ea;
while (ea--) {
char c;
cin >> c;
if (c == 'L') {
if (t != editor.begin()) {
t--;
}
} else if (c == 'D') {
if (t != editor.end()) {
t++;
}
} else if (c == 'B') {
if (t != editor.begin()) {
t--;
t = editor.erase(t);
}
} else if (c == 'P') {
char content;
cin >> content;
editor.insert(t, content);
}
}
for (auto e : editor) {
cout << e;
}
}
최근댓글