-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q10799.java
39 lines (32 loc) · 872 Bytes
/
Q10799.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
31
32
33
34
35
36
37
38
39
package olympiad;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Q10799 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String str = br.readLine();
int cnt = 0;
int rs = 0;
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if(ch == '('){
char nextCh = str.charAt(i + 1);
if(nextCh == ')'){ //cutting
rs += cnt;
i++;
} else // (°ýÈ£
cnt++;
} else if(ch == ')'){ // )°ýÈ£
cnt--;
rs++;
}
}
bw.write(rs + "\n");
br.close();
bw.close();
}
}