blob: d51e0d3f57eaa5d9f4bfef594c9c24f567edc617 (
plain) (
blame)
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
40
41
|
var
s: ansistring;
function bracket(
s: ansistring;
l, h: integer
): integer;
var
i, tmp: integer;
begin
if l > h then
exit(0);
bracket := -1;
repeat
tmp := 0;
for i := l to h do
begin
if s[i] = '(' then
dec(tmp)
else
inc(tmp);
if tmp = 0 then
begin
tmp := succ(bracket(s, succ(l), pred(i)));
if tmp > bracket then
bracket := tmp;
l := succ(i);
break
end
end;
until l > h;
end;
begin
readln(s);
writeln(bracket(s, 1, length(s)))
end.
|