-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_1406
More file actions
63 lines (51 loc) · 1.7 KB
/
BAEKJOON_1406
File metadata and controls
63 lines (51 loc) · 1.7 KB
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
55
56
57
58
59
60
61
62
63
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder(br.readLine()); //test할 문자열
int cmd = Integer.parseInt(br.readLine()); //몇개의 명령어를 쓸거냐
Stack<Character> s1 = new Stack<>();
Stack<Character> s2 = new Stack<>();
for(int i=0; i<sb.length(); i++){
s1.push(sb.charAt(i));
}
char c;
for(int i=0; i<cmd; i++){
String str = br.readLine();
switch(str.charAt(0)){
case 'L':
if(s1.size()==0)break;
c=s1.peek();
s1.pop();
s2.push(c);
break;
case 'B':
if(s1.size()==0)break;
s1.pop();
break;
case 'D':
if(s2.size()==0)break;
c=s2.peek();
s2.pop();
s1.push(c);
break;
case 'P':
c= str.charAt(2);
s1.push(c);
break;
}
}
while(!s1.isEmpty()){
s2.push(s1.peek());
s1.pop();
}
StringBuilder sb2 =new StringBuilder();
while(!s2.isEmpty()){
sb2.append(s2.peek());
s2.pop();
}
System.out.println(sb2.toString());
}
}