-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1406.cpp
48 lines (45 loc) · 998 Bytes
/
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
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
char a[600000];
int main(){
scanf("%s", a);
stack<char> left, right;
int m = strlen(a);
for(int i = 0; i<m; i++){
left.push(a[i]);
}
int n;
scanf("%d", &n);
while(n--){
char com;
scanf(" %c", &com);
if(com == 'L'){
if(!left.empty()){
right.push(left.top());
left.pop();
}
}else if(com == 'D'){
if(!right.empty()){
left.push(right.top());
right.pop();
}
}else if(com == 'B'){
if(!left.empty()){
left.pop();
}
}else if(com == 'P'){
scanf(" %c", &com);
left.push(com);
}
}
while(!left.empty()){
right.push(left.top());
left.pop();
}
while(!right.empty()){
printf("%c", right.top());
right.pop();
}
}