백준/백준-C++
1406번: 에디터
Beabletoet
2017. 5. 26. 15:05
#include <iostream>
#include <list>
#include <string>
using namespace std;
int main()
{
list<char> word;
list<char>::iterator cursor, x;
char a[100001], command[4];
int n;
cin >> a >> n;
for (int i = 0; a[i] != '\0'; ++i)
word.push_back(a[i]);
cursor = word.end();
cin.ignore();
for (int i = 0; i < n; ++i)
{
cin.getline(command, 4);
if (command[0] == 'L')
(cursor != word.begin()) ? --cursor : cursor ;
else if (command[0] == 'D')
(cursor == word.end()) ? cursor : ++cursor;
else if (command[0] == 'B')
{
if (cursor != word.begin())
{
x = cursor;
--x;
word.erase(x);
}
}
else if (command[0] == 'P')
word.insert(cursor, command[2]);
}
for (list<char>::iterator i = word.begin(); i != word.end(); ++i)
cout << *i;
}