-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNo_9012.java
More file actions
47 lines (41 loc) · 1.48 KB
/
No_9012.java
File metadata and controls
47 lines (41 loc) · 1.48 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
46
47
/*
Problem_9012_괄호
https://www.acmicpc.net/problem/9012
*/
import java.io.*;
public class No_9012 {
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 testData = Integer.parseInt(br.readLine());
int countToken = -1;
boolean isCheck = false;
for(int repeat = 0; repeat < testData; repeat++) {
String str = br.readLine();
countToken = 0;
confirm : for (int i = 0; i < str.length(); i++) {
if (countToken < 0) {//')'이 먼저 나오거나 판별 중에 VPS가 아니라고 판단되는 경우
isCheck = false;
break confirm;
}
if (str.charAt(i) == '(') {
++countToken;
}
else if (str.charAt(i) == ')') {
--countToken;
}
}
/*
countToken이 0이면 VPS이고 0보다 크거나 작으면 VPS가 아니다.
*/
if (countToken == 0) { isCheck = true; }
else if (countToken > 0) { isCheck = false; }
else { isCheck = false; }
if (isCheck) { bw.write("YES\n"); }
else { bw.write("NO\n"); }
}
bw.flush();
bw.close();
br.close();
}
}