about summary refs log tree commit diff
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
parentd40c9b81db3caff8ecca79df92241bc0c28a468c (diff)
downloadcp-f2d4bc6b7c302dee2d84a3acf84b83b5a98c45fa.tar.gz
More parentheses
-rw-r--r--THT/B/QG-2016/remainder.scm3
-rw-r--r--daily/302hard/bargroup.pas32
-rw-r--r--others/other/spiral.pas13
-rw-r--r--others/volume1/037.pas41
4 files changed, 56 insertions, 33 deletions
diff --git a/THT/B/QG-2016/remainder.scm b/THT/B/QG-2016/remainder.scm
index 3df8468..8360da1 100644
--- a/THT/B/QG-2016/remainder.scm
+++ b/THT/B/QG-2016/remainder.scm
@@ -3,8 +3,7 @@
   (cond ((= y 1) (remainder x z))
          ((= (remainder y 2) 0) (remainder (sqr (pow x (quotient y 2) z)) z))
          (else (remainder (* (sqr (pow x (quotient y 2) z)) x) z))))
-(with-output-to-file "REMAINDER.TXT" (lambda ()
-                                       (for-each
+(with-output-to-file "REMAINDER.TXT" (lambda () (for-each
   (lambda (l)
     (let* ((a (integer-expt 10 (string-length (number->string (list-ref l 0)))))
            (m (* (list-ref l 2) (- a 1)))
diff --git a/daily/302hard/bargroup.pas b/daily/302hard/bargroup.pas
index 295c458..de3c46a 100644
--- a/daily/302hard/bargroup.pas
+++ b/daily/302hard/bargroup.pas
@@ -1,4 +1,4 @@
-uses math, sysutils;
+uses math, strutils, sysutils;
 
 var
   minx, maxx, miny, maxy, stepx, stepy, i, x0, f: integer;
@@ -22,18 +22,6 @@ function gcd(a, b: integer): integer;
   end;
 
 
-function rjust(
-  s: string;
-  width: byte;
-  fill: char
-): string;
-  begin
-    while length(s) < width do
-      s := fill + s;
-    rjust := s
-  end;
-
-
 begin
   read(minx, maxx, miny, maxy, stepx, n);
   setlength(raw_freq, maxx - minx + 1);
@@ -69,19 +57,21 @@ begin
   setlength(xtrue, length(freq));
   for i := 0 to length(freq) - 1 do
     begin
-      xtrue[i] := rjust('', length(inttostr(minx + stepx * i)), '*');
-      xfalse[i] := rjust('', length(inttostr(minx + stepx * i)), ' ');
+      xtrue[i] := addchar('*', '', length(inttostr(minx + stepx * i)));
+      xfalse[i] := addchar(' ', '', length(inttostr(minx + stepx * i)));
       for j := 1 to stepx - 1 do
         begin
-          xtrue[i] := xtrue[i] +
-                      rjust('', length(inttostr(minx + stepx*i + j)) + 1, '*');
-          xfalse[i] := xfalse[i] +
-                       rjust('', length(inttostr(minx + stepx*i + j)) + 1, ' ')
+          xtrue[i] :=
+            xtrue[i] +
+            addchar('*', '', length(inttostr(minx + stepx*i + j)) + 1);
+          xfalse[i] :=
+            xfalse[i] +
+            addchar(' ', '', length(inttostr(minx + stepx*i + j)) + 1)
         end
     end;
 
   repeat
-    write(rjust(inttostr(maxy), lenf, ' '));
+    write(addchar(' ', inttostr(maxy), lenf), ' ');
     for i := 0 to length(freq) - 2 do
       begin
         if freq[i] >= maxy then
@@ -97,7 +87,7 @@ begin
     dec(maxy, stepy)
   until maxy < miny;
 
-  write(rjust('', lenf, ' '));
+  write(addchar(' ', '', lenf + 1));
   for i := minx to maxx - 1 do
     write(i, ' ');
   writeln(maxx)
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.