-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJAlgo_4949.java
More file actions
45 lines (39 loc) · 1.39 KB
/
Copy pathBJAlgo_4949.java
File metadata and controls
45 lines (39 loc) · 1.39 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class BJAlgo_4949 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
List stack = new ArrayList();
String[] text = br.readLine().split("");
if (".".equals(text[0])) {
break;
}
for (int i = 0; i < text.length; i++) {
String s = text[i];
if ("(".equals(s) || "[".equals(s)) {
stack.add(s);
} else if (")".equals(s)) {
if (stack.size() > 0 && "(".equals(stack.get(stack.size() - 1))) {
stack.remove(stack.size() - 1);
} else {
stack.add(s);
}
} else if ("]".equals(s)) {
if (stack.size() > 0 && "[".equals(stack.get(stack.size() - 1))) {
stack.remove(stack.size() - 1);
} else {
stack.add(s);
}
}
}
if (stack.size() > 0) {
System.out.println("no");
} else {
System.out.println("yes");
}
}
}
}