-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10799.java
More file actions
34 lines (29 loc) · 837 Bytes
/
10799.java
File metadata and controls
34 lines (29 loc) · 837 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
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String a = br.readLine();
StringBuilder format = new StringBuilder();
for(int i=0;i<a.length()-2;i++) {
if((a.charAt(i)== '(') && (a.charAt(i+1)== ')')) {
format.append('1');
i++;
}else {
format.append(a.charAt(i));
}
}
format.append(')');
int add=0;int sum=0;
for(int i=0;i<format.length()-1;i++) {
if(format.charAt(i)=='(') {
add++;sum++;
}else if(format.charAt(i)==')'){
add--;
}else if(format.charAt(i)=='1') {
sum += add;
}
}
System.out.println(sum);
}
}