-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1406.cpp
More file actions
43 lines (37 loc) · 708 Bytes
/
1406.cpp
File metadata and controls
43 lines (37 loc) · 708 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
#include "stdafx.h"
#include <string>
#include <iostream>
#include <list>
using namespace std;
int main() {
int n;
string s;
cin >> s;
cin >> n;
list<char> l(s.begin(), s.end());
list<char>::iterator pointer_iter = l.end();
while (n--) {
char c, c2;
cin >> c;
if (c == 'P') {
cin >> c2;
l.insert(pointer_iter, c2);
}
else if (c == 'L') {
if (pointer_iter != l.begin()) pointer_iter--;
}
else if (c == 'D') {
if (pointer_iter != l.end()) pointer_iter++;
}
else if (c == 'B') {
if (pointer_iter != l.begin()) {
pointer_iter--;
pointer_iter = l.erase(pointer_iter);
//pointer_iter++;
}
}
}
for (auto &x : l) cout << x;
cout << endl;
return 0;
}