Notice
Recent Posts
Recent Comments
Link
반응형
변명은 만개 결과는 한개
[백준 9012] 괄호 (java) 본문
728x90
반응형
https://www.acmicpc.net/problem/9012
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(br.readLine());
for (int i = 0; i < N; i++) {
String[] strs = br.readLine().split("");
int openCount = 0;
for (int j = 0; j < strs.length; j++) {
if (strs[j].equals("(")) {
openCount++;
} else {
openCount--;
if(openCount<0){
openCount-=1000;
}
}
}
if(openCount == 0){
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
728x90
반응형