diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-02-20 10:33:39 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-02-20 10:33:39 +0700 |
commit | f2d4bc6b7c302dee2d84a3acf84b83b5a98c45fa (patch) | |
tree | d40c38af8709309f51f3cf82bcbc2b44dbfaa3b7 /others | |
parent | d40c9b81db3caff8ecca79df92241bc0c28a468c (diff) | |
download | cp-f2d4bc6b7c302dee2d84a3acf84b83b5a98c45fa.tar.gz |
More parentheses
Diffstat (limited to 'others')
-rw-r--r-- | others/other/spiral.pas | 13 | ||||
-rw-r--r-- | others/volume1/037.pas | 41 |
2 files changed, 44 insertions, 10 deletions
diff --git a/others/other/spiral.pas b/others/other/spiral.pas index 3f8fc57..819b9b2 100644 --- a/others/other/spiral.pas +++ b/others/other/spiral.pas @@ -1,4 +1,4 @@ -uses sysutils; +uses strutils, sysutils; const direction: array[0..3, 0..1] of int8 = ((0, 1), (1, 0), (0, -1), (-1, 0)); @@ -21,13 +21,6 @@ function mt(x, y: int16): boolean; mt := true end; -function rjust(i: int32; len: int8): string; - begin - rjust := inttostr(i); - while length(rjust) < len do - rjust := ' ' + rjust - end; - begin assign(f, 'SPIRAL.INP'); reset(f); @@ -63,8 +56,8 @@ begin for x := 0 to m - 1 do begin for y := 0 to n - 2 do - write(f, rjust(a[x][y], d), ' '); - writeln(f, rjust(a[x][n - 1], d)) + write(f, padleft(inttostr(a[x][y]), d), ' '); + writeln(f, padleft(inttostr(a[x][n - 1]), d)) end; close(f) end. 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. |