-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1406.cpp
54 lines (51 loc) · 972 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
49
50
51
52
53
54
#include <cstdio>
#include <stack>
using namespace std;
stack<char> b,a;
char c;
int n,x;
int main() {
while(true){
c = getchar();
if(c=='\n') break;
b.push(c);
}
scanf("%d",&n);
getchar();
for(int i=0;i<n;++i){
c = getchar();
switch(c){
case 'L':
if(!b.empty()){
a.push(b.top());
b.pop();
}
break;
case 'D':
if(!a.empty()){
b.push(a.top());
a.pop();
}
break;
case 'B':
if(!b.empty())
b.pop();
break;
case 'P':
getchar();
c = getchar();
b.push(c);
break;
}
getchar();
}
while(!b.empty()){
a.push(b.top());
b.pop();
}
while(!a.empty()){
printf("%c",a.top());
a.pop();
}
return 0;
}