-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
31 lines (24 loc) ยท 959 Bytes
/
Copy pathSolution.java
File metadata and controls
31 lines (24 loc) ยท 959 Bytes
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
package Stack.swea1218;
import java.io.*;
import java.util.*;
public class Solution {
final static int T = 10;
static String pre = "([{<", post = ")]}>";
static Stack<Character> s = new Stack<>();
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/Stack/swea1218/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int t = 1; t <= T; t++) {
int n = Integer.parseInt(br.readLine());
String input = br.readLine();
for (int i = 0; i < n; i++) {
char cur = input.charAt(i);
if (pre.indexOf(cur) >= 0) s.push(cur);
else if (!s.isEmpty() && pre.indexOf(s.peek()) == post.indexOf(cur)) s.pop();
else break;
}
System.out.println("#" + t + " " + (s.isEmpty() ? 1 : 0));
s.clear();
}
}
}