-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1406.cpp
More file actions
46 lines (40 loc) · 743 Bytes
/
1406.cpp
File metadata and controls
46 lines (40 loc) · 743 Bytes
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
#include <iostream>
#include <list>
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int m;
string input;
cin >>input>>m;
list<char> editer(input.begin(), input.end());
auto cursor = editer.end();
char word,p;
while (m--){
cin >> word;
if(word == 'L')
{
if(cursor != editer.begin())
cursor--;
}
else if(word == 'D')
{
if(cursor != editer.end())
cursor++;
}
else if(word == 'B')
{
if(cursor != editer.begin())
cursor = editer.erase(--cursor);
}
else if(word == 'P')
{
cin >> p;
editer.insert(cursor,p);
}
}
for(auto it : editer){
cout << it;
}
return 0;
}