-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyLogger.java
More file actions
49 lines (39 loc) · 1.11 KB
/
KeyLogger.java
File metadata and controls
49 lines (39 loc) · 1.11 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
package CodeTest;
import java.util.Scanner;
import java.util.Stack;
//백준 5397번
//스택
public class KeyLogger {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testcase = sc.nextInt();
for (int i = 0; i < testcase; i++) {
String str = sc.next();
Stack<Character> left = new Stack<Character>();
Stack<Character> right = new Stack<Character>();
for (int j = 0; j < str.length(); j++) {
//char input = str.charAt(j);
if (str.charAt(j) == '<') {
if(!left.isEmpty())
right.push(left.pop());
} else if (str.charAt(j) == '-') {
if(!left.isEmpty())
left.pop();
} else if (str.charAt(j) == '>') {
if(!right.isEmpty())
left.push(right.pop());
} else {
left.push(str.charAt(j));
}
}
while(!left.isEmpty()){
right.push(left.pop());
}
StringBuilder result = new StringBuilder();
while(!right.isEmpty()){
result.append(right.pop());
}
System.out.println(result);
}
}
}