-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1406.cpp
62 lines (58 loc) · 1.19 KB
/
1406.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 1406. 에디터
// 2020.04.11
// 링크드 리스트
#include<iostream>
#include<string>
#include<list>
using namespace std;
int main()
{
string s;
cin >> s;
list<char> list;
for (int i = 0; i < s.size(); i++)
{
list.push_back(s[i]);
}
auto cur = list.end();
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
char order;
cin >> order;
switch (order)
{
case 'L': // 왼쪽으로
if (cur != list.begin())
{
cur--;
}
break;
case 'D': // 오른쪽으로
if (cur != list.end())
{
cur++;
}
break;
case 'B': // 왼쪽에 있는 문자 삭제
if (cur != list.begin())
{
cur--;
cur = list.erase(cur);
}
break;
case 'P': // 왼쪽에 문자 추가
char tmp;
cin >> tmp;
list.insert(cur, tmp);
break;
}
}
for (auto iter = list.begin(); iter != list.end(); iter++)
{
cout << *iter;
}
cout << endl;
return 0;
}