-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package B_200_자료구조1; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Stack; | ||
import java.util.StringTokenizer; | ||
|
||
public class B_1406_에디터 { | ||
|
||
public static void main(String args[]) throws NumberFormatException, IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = null; | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
String L = br.readLine(); | ||
char[] la = L.toCharArray(); | ||
|
||
int C = Integer.parseInt(br.readLine()); | ||
Stack<Character> stack = new Stack<>(); | ||
Stack<Character> res = new Stack<>(); | ||
|
||
for(int i=0; i<la.length; i++) stack.add(la[i]); | ||
|
||
|
||
for(int i=0; i<C; i++) { | ||
st = new StringTokenizer(br.readLine(), " "); | ||
String order = st.nextToken(); | ||
if(order.equals("P")) stack.add(st.nextToken().toCharArray()[0]); | ||
else if(order.equals("B")) { | ||
if(!stack.isEmpty()) stack.pop(); | ||
}else if(order.equals("D")) { | ||
if(!res.isEmpty()) stack.add(res.pop()); | ||
}else { | ||
if(!stack.isEmpty()) res.add(stack.pop()); | ||
} | ||
} | ||
|
||
while(!stack.isEmpty()) res.add(stack.pop()); | ||
while(!res.isEmpty()) sb.append(res.pop()); | ||
System.out.println(sb); | ||
} | ||
|
||
} |