-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay4.java
More file actions
36 lines (34 loc) · 877 Bytes
/
Day4.java
File metadata and controls
36 lines (34 loc) · 877 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
package Algorithm;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Stack;
public class Day4{
public static void main(String[] strings) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
for(int i=0; i<N; i++) {
Stack<String> ss = new Stack<>();
boolean VPS = true;
StringTokenizer st = new StringTokenizer(br.readLine(), "()", true);
while(st.hasMoreTokens()) {
String element = st.nextToken();
if(element.equals("(")) {
ss.push(element);
}else {
if(ss.isEmpty()) {
VPS = false;
break;
}
ss.pop();
}
}
if(ss.isEmpty() && VPS == true) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}