-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy path[02]_3.java
50 lines (43 loc) · 1.08 KB
/
[02]_3.java
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int tc;
tc = Integer.parseInt(br.readLine());
while (tc-- > 0) {
String s;
s = br.readLine();
Stack<Character> left = new Stack<Character>();
Stack<Character> right = new Stack<Character>();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '-') {
if (!left.empty()) left.pop();
}
else if (s.charAt(i) == '<') {
if (!left.empty()) {
right.push(left.pop());
}
}
else if (s.charAt(i) == '>') {
if (!right.empty()) {
left.push(right.pop());
}
}
else {
left.push(s.charAt(i));
}
}
StringBuilder result = new StringBuilder();
while (!right.empty()) {
left.push(right.pop());
}
while (!left.empty()) {
result.append(left.pop());
}
System.out.println(result.reverse().toString());
}
}
}