Deep_Dev

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AYGtoa3qARcDFARC#none 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 

 

 


(์ด๋‚˜ )๊ฐ€ ์žˆ์œผ๋ฉด ๋ฌด์กฐ๊ฑด ++ ํ•˜๊ณ  

() ์ด๋ ‡๊ฒŒ ์™„์„ฑ๋œ ๊ณต์ด ์žˆ์œผ๋ฉด  --

 

 

 

import java.util.Scanner;
class Solution{
    public static void main(String args[]) throws Exception{
         Scanner kb = new Scanner(System.in);
        int T=kb.nextInt();
        int[] arr=new int[T];
        for(int test_case=0; test_case<T; test_case++) {
            int answer=0;
            int temp=0;
           String s=kb.next();
           for(int i=0; i<s.length(); i++){
               if(s.charAt(i)=='('||s.charAt(i)==')') {
                   answer++;
               }
           }
           for(int i=0; i<s.length()-1; i++){
               if(s.charAt(i)=='('&&s.charAt(i+1)==')')
                   temp++;
           }
           arr[test_case]=answer-temp;
        }
        for(int i=0; i<arr.length; i++) System.out.println("#"+(i+1)+" "+arr[i]);
    }
}