https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AYGtoa3qARcDFARC#none
(์ด๋ )๊ฐ ์์ผ๋ฉด ๋ฌด์กฐ๊ฑด ++ ํ๊ณ
() ์ด๋ ๊ฒ ์์ฑ๋ ๊ณต์ด ์์ผ๋ฉด --
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]);
}
}
'๐ ์ฝ๋ฉํ ์คํธ > ๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 1 : ์ซ์ ์ง๊ถ (0) | 2022.11.04 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 0 : ์ง์ฌ๊ฐํ ๋์ด ๊ตฌํ๊ธฐ (0) | 2022.11.04 |
[SWEA][JAVA]D3 : ๋ฐ๋ฐ (0) | 2022.11.03 |
[SWEA][JAVA]D2 : ์ค์ ํ๊ท ๊ฐ ๊ตฌํ๊ธฐ (0) | 2022.11.03 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 1 : ์ฝ๋ผ ๋ฌธ์ (0) | 2022.11.03 |