-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_10799
More file actions
36 lines (29 loc) · 890 Bytes
/
BAEKJOON_10799
File metadata and controls
36 lines (29 loc) · 890 Bytes
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
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
Stack<Integer> s = new Stack<>();
StringBuilder sb= new StringBuilder(br.readLine());
int sum=0;
for(int i=0; i<sb.length(); i++){
char c = sb.charAt(i);
if(c=='('){
s.push(i);
}else{
if(i-1 == s.peek()){
s.pop();
sum+=s.size();
}else{
s.pop();
sum+=1;
}
}
}
s.clear();
bw.write(String.valueOf(sum));
bw.flush();
bw.close();
}
}