-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
29 lines (24 loc) ยท 763 Bytes
/
Copy pathMain.java
File metadata and controls
29 lines (24 loc) ยท 763 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
package Stack.P10799;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/Stack/P10799/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int ans = 0, cnt = 0, len = s.length(), i = 0;
while (i < len) {
if (s.charAt(i) == '(' && s.charAt(i+1) == ')') {
ans += cnt;
i += 2;
} else {
if (s.charAt(i) == '(') cnt ++;
else {
ans ++;
cnt --;
}
i++;
}
}
System.out.println(ans);
}
}