-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1406-list.cpp
48 lines (39 loc) · 927 Bytes
/
1406-list.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
#include <iostream>
#include <string>
#include <list>
using namespace std;
int main() {
string s;
getline(cin, s);
list<char> char_list;
for (char c : s)
char_list.push_back(c);
int M;
cin >> M;
cin.ignore();
auto cursor = char_list.cend();
for (int i = 0; i < M; ++i) {
string command;
getline(cin, command);
switch (command[0]) {
case 'L':
if (cursor != char_list.cbegin())
--cursor;
break;
case 'D':
if (cursor != char_list.cend())
++cursor;
break;
case 'B':
if (cursor != char_list.cbegin())
cursor = char_list.erase(--cursor);
break;
case 'P':
char_list.insert(cursor, command[2]);
break;
}
}
for (char c : char_list)
cout << c;
return 0;
}