forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbac9012.java
More file actions
34 lines (28 loc) · 960 Bytes
/
bac9012.java
File metadata and controls
34 lines (28 loc) · 960 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
32
33
34
import java.util.*;
public class bac9012 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int N = Integer.parseInt(sc.nextLine());
ArrayList<String> strArr = new ArrayList<>();
for(int i = 0; i < N ; i++)
strArr.add(sc.nextLine());
for(int i = 0; i < N ; i++) {
Stack stack = new Stack();
try {
for(int j = 0; j < strArr.get(i).length(); j++) {
if(strArr.get(i).charAt(j)=='(')
stack.push(strArr.get(i).charAt(j));
else {
stack.pop();
}
}
if(stack.isEmpty())
System.out.println("YES");
else
System.out.println("NO");
} catch(Exception e) {
System.out.println("NO");
}
}
}
}