VioletaBabel
1406번: 에디터 본문
#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;
}
'백준 > 백준-C++' 카테고리의 다른 글
11004번: K번째 수 (0) | 2017.05.26 |
---|---|
10828번: 스택 (0) | 2017.05.26 |
1158번: 조세퍼스 문제 (0) | 2017.05.26 |
3622번: 어떤 호박의 할로윈 여행 (0) | 2017.05.26 |
1057번: 토너먼트 (0) | 2017.05.25 |
Comments