-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD4_5432_스택.java
30 lines (27 loc) · 974 Bytes
/
D4_5432_스택.java
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
package com.swea.D4;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class D4_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 t = 1; t <= T; ++t) {
int count = 0;
char[] ch = br.readLine().toCharArray();
Stack<Character> stack = new Stack<>();
stack.push(ch[0]);
for (int i = 1; i < ch.length; ++i) {
char c = ch[i];
if (c == '(') stack.push(c);
else {
stack.pop();
if (ch[i - 1] == '(' && ch[i] == ')') count += stack.size();
else count += 1;
}
}
System.out.println("#" + t + " " + count);
}
}
}