-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJAlgo_9012.java
More file actions
37 lines (31 loc) · 1.12 KB
/
Copy pathBJAlgo_9012.java
File metadata and controls
37 lines (31 loc) · 1.12 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class BJAlgo_9012 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(br.readLine());
for (int i = 0; i < count; i++) {
List stack = new ArrayList();
String[] ps = br.readLine().split("");
for (int j = 0; j < ps.length; j++) {
String item = String.valueOf(ps[j]);
if ("(".equals(item)) {
stack.add(item);
} else if (")".equals(item)) {
if (stack.size() > 0 && "(".equals(stack.get(stack.size() - 1))) {
stack.remove(stack.size() - 1);
} else {
stack.add(item);
}
}
}
if (stack.size() > 0) {
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
}