-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpb9012.java
More file actions
47 lines (40 loc) · 971 Bytes
/
pb9012.java
File metadata and controls
47 lines (40 loc) · 971 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
35
36
37
38
39
40
41
42
43
44
45
46
47
package algo_baek;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Stack;
// 성공
public class pb9012 {
public static void main (String args[]) throws IOException {
BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter BW = new BufferedWriter(new OutputStreamWriter(System.out));
int T = Integer.parseInt(BR.readLine());
String s;
for(int i = 0; i < T; i++) {
s = BR.readLine();
Stack st = new Stack();
for(int j = 0; j< s.length(); j++) {
if( s.charAt(j) == '(') {
st.push("(");
} else if( s.charAt(j) == ')') {
if(st.isEmpty()) {
st.push("x");
break;
} else {
st.pop();
}
}
}
if(st.isEmpty()) {
BW.write("YES\n");
} else {
BW.write("NO\n");
}
}
BR.close();
BW.flush();
BW.close();
}
}