-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim.java
More file actions
32 lines (31 loc) · 1.11 KB
/
sim.java
File metadata and controls
32 lines (31 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
import java.util.*;
import java.io.*;
public class sim {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int cases = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
Boolean front = false;
int cursor = -1;
for (int x = 0; x < cases; ++x) {
for (char c : br.readLine().toCharArray()) {
if (c == '<') {
if (!sb.isEmpty()) {
sb.deleteCharAt(cursor);
cursor--;
}
} else if (c == '[') {
front = true; cursor = -1;
} else if (c == ']') {
front = false; cursor = sb.length() - 1;
} else {
if (front) { cursor++; sb.insert(cursor, c); }
else { sb.append(c); cursor++;}
}
}
}
pw.println(sb.toString());
pw.flush();
}
}