https://www.acmicpc.net/problem/4889
package BOJ.etc;
import java.awt.print.Pageable;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class BOJ_4889 {
private static final char OPEN = '{';
private static final char CLOSE = '}';
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = 1;
while(true){
String command = br.readLine();
if(command.charAt(0) == '-'){
break;
}
int cnt = 0;
int result = 0;
for(int i = 0 ; i < command.length() ; i++){
char ch = command.charAt(i);
if(ch == OPEN){
cnt++;
}else {
cnt--;
}
if(cnt < 0){
result++;
cnt += 2;
}
}
if(cnt > 0){
result += cnt / 2;
}
System.out.println(num + ". " + result);
num++;
}
}
}
'알고리즘' 카테고리의 다른 글
백준 20162번 간식 파티 (JAVA) (0) | 2023.03.01 |
---|---|
백준 15723번 n단 논법 (JAVA) (0) | 2023.02.28 |
백준 1326번 폴짝폴짝 (JAVA) (0) | 2023.02.26 |
프로그래머스 배열 뒤집기 (JAVA) (0) | 2023.02.25 |
백준 17266번 어두운 굴다리 (JAVA) (0) | 2023.02.24 |