๐ ์ฝ๋ฉํ
์คํธ/๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค
[SWEA][JAVA]D3 : ์ก์ด
deep_lee
2022. 11. 3. 17:53
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]);
}
}