Advertisement
savrasov

skobk

Nov 20th, 2016
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.18 KB | None | 0 0
  1. program skobki;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. type
  9.   pr = record
  10.     b, e: integer;
  11.   end;
  12.  
  13. var
  14.   a: array [1..500005] of pr;
  15.   b: array [1..500005] of integer;
  16.   i, r, t, n, k: integer;
  17.   f: pr;
  18.   s: string;
  19.  
  20. function skob(j: integer): integer;
  21. var
  22.   f : integer;
  23. begin
  24.   f := 1;
  25.   inc(j);
  26.   while (f <> 0) and (j <= length(s)) do
  27.   begin
  28.     if (s[j] = '(') then inc(f)
  29.     else dec(f);
  30.     inc(j);
  31.   end;
  32.   if (f = 0) then skob := j - 1
  33.   else skob := 0;
  34. end;
  35.  
  36. begin
  37.   readln(s);
  38.   n := -1;
  39.   i := 1;
  40.   r := 0;
  41.   k := 0;
  42.   while (i <= length(s)) do
  43.     if (s[i] = ')') or (skob(i) = 0) then inc(i)
  44.     else
  45.     begin
  46.       inc(r);
  47.       a[r].b := i;
  48.       a[r].e := skob(i);
  49.       i := a[r].e + 1;
  50.     end;
  51.   if(r <> 0) then f := a[1];
  52.   t := 1;
  53.   for i := 2 to r do
  54.     if (f.e = a[i].b - 1) then f.e := a[i].e
  55.     else
  56.     begin
  57.       b[t] := f.e - f.b + 1;
  58.       f := a[i];
  59.       inc(t);
  60.     end;
  61.   if (r <> 0) then b[t] := f.e - f.b + 1;
  62.   for i := 1 to t do
  63.   if (n = b[i]) then inc(k)
  64.   else if (n < b[i]) then
  65.   begin
  66.     n := b[i];
  67.     k := 1;
  68.   end;
  69.   if (n = -1) then writeln('0 1')
  70.   else writeln(n, ' ', k);
  71. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement