about summary refs log tree commit diff
path: root/others/volume1
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-20 10:33:39 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-20 10:33:39 +0700
commitf2d4bc6b7c302dee2d84a3acf84b83b5a98c45fa (patch)
treed40c38af8709309f51f3cf82bcbc2b44dbfaa3b7 /others/volume1
parentd40c9b81db3caff8ecca79df92241bc0c28a468c (diff)
downloadcp-f2d4bc6b7c302dee2d84a3acf84b83b5a98c45fa.tar.gz
More parentheses
Diffstat (limited to 'others/volume1')
-rw-r--r--others/volume1/037.pas41
1 files changed, 41 insertions, 0 deletions
diff --git a/others/volume1/037.pas b/others/volume1/037.pas
new file mode 100644
index 0000000..d51e0d3
--- /dev/null
+++ b/others/volume1/037.pas
@@ -0,0 +1,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.