문제 보기 >> 5432. 쇠막대기 자르기
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 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; public class Solution_5432_쇠막대기자르기 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); for(int tc = 1 ;tc<= T ;tc++) { String str = br.readLine(); char now; char[] arr = new char[str.length()]; int piece = 0; int stick=0; for(int i=0;i<str.length();i++) { now = str.charAt(i); if(now==')') { char pre = str.charAt(i-1); if(pre == '(') { //레이저 stick--; piece += stick; } else { stick --; piece++; } } if(now == '(') { stick++; } } System.out.println("#"+tc+" "+piece); }//testcase end }// end of main } | cs |
'Algorithm Problem Solving' 카테고리의 다른 글
[BOJ]1389: 케빈 베이컨의 6단계 법칙 (0) | 2019.02.08 |
---|---|
[정올] 1809 : 탑 (0) | 2019.01.22 |
1218. [S/W 문제해결 기본] 4일차 - 괄호 짝짓기 (0) | 2019.01.15 |
[BOJ] 1018 : 체스판 다시 칠하기 (0) | 2019.01.11 |
1206. [S/W 문제해결 기본] 1일차 - View (0) | 2019.01.11 |