diff options
-rw-r--r-- | others/volume1/016.pas | 24 | ||||
-rw-r--r-- | others/volume1/019.pas | 21 | ||||
-rw-r--r-- | others/volume1/021.pas | 29 | ||||
-rw-r--r-- | others/volume1/022.pas | 31 | ||||
-rw-r--r-- | others/volume1/033.pas | 22 | ||||
-rw-r--r-- | others/volume1/096.pas | 28 | ||||
-rw-r--r-- | others/volume1/124.pas | 28 | ||||
-rw-r--r-- | others/volume1/clib.pas | 32 |
8 files changed, 189 insertions, 26 deletions
diff --git a/others/volume1/016.pas b/others/volume1/016.pas new file mode 100644 index 0000000..e50eef0 --- /dev/null +++ b/others/volume1/016.pas @@ -0,0 +1,24 @@ +var + s, z: ansistring; + i, j, k: int16; + +begin + readln(s); + readln(k); + setlength(z, length(s)); + i := 0; + j := 0; + repeat + inc(i); + while (j > 0) and + (k > 0) and + (s[i] > z[j]) do + begin + dec(j); + dec(k) + end; + inc(j); + z[j] := s[i] + until i = length(s); + writeln(z) +end. diff --git a/others/volume1/019.pas b/others/volume1/019.pas new file mode 100644 index 0000000..1c80fcc --- /dev/null +++ b/others/volume1/019.pas @@ -0,0 +1,21 @@ +uses clib; + +var + a: intar; + i: int8; + n, m: int64; + +begin + readln(n); + setlength(a, 87); + for i := 2 to 88 do + a[i - 1] := fibonacci[i]; + while n > 0 do + begin + m := bisect_left(a, n); + if a[m] > n then + m := m - 1; + writeln(a[m]); + n := n - a[m] + end +end. diff --git a/others/volume1/021.pas b/others/volume1/021.pas new file mode 100644 index 0000000..f20aa7c --- /dev/null +++ b/others/volume1/021.pas @@ -0,0 +1,29 @@ +var + i, n: int32; + +function isperfect(n: int32): boolean; + var + i, s, m: int32; + begin + m := trunc(sqrt(n)); + if n mod m > 0 then + s := 1 + else if n = m * m then + s := 1 + m + else + s := 1 + m + n div m; + for i := 2 to m - 1 do + if n mod i = 0 then + s := s + i + n div i; + if s = n then + isperfect := true + else + isperfect := false + end; + +begin + readln(n); + for i := 2 to n do + if isperfect(i) then + writeln(i) +end. diff --git a/others/volume1/022.pas b/others/volume1/022.pas new file mode 100644 index 0000000..87c1d15 --- /dev/null +++ b/others/volume1/022.pas @@ -0,0 +1,31 @@ +var + s: array[1..1000000] of int32; + m, n, i, j: int32; + +begin + readln(m); + s[1] := 0; + for i := 2 to m do + begin + n := trunc(sqrt(i)); + if i mod n > 0 then + s[i] := 1 + else if i = n * n then + s[i] := 1 + n + else + s[i] := 1 + n + i div n; + for j := 2 to n - 1 do + if i mod j = 0 then + inc(s[i], j + i div j) + end; + + j := 0; + for i := 2 to m do + if (i <> s[i]) and + (s[i] <= 1000000) and + (i = s[s[i]]) then + begin writeln(i, ' ', s[i]); + inc(j); + end; + writeln(j div 2) +end. diff --git a/others/volume1/033.pas b/others/volume1/033.pas new file mode 100644 index 0000000..2d8a77a --- /dev/null +++ b/others/volume1/033.pas @@ -0,0 +1,22 @@ +uses clib; + +var + n, i: int16; + a: intar; + max, tmp: int64; + +begin + readln(n); + setlength(a, n * 2); + for i := 0 to n * 2 - 1 do + read(a[i]); + qsort(a); + max := a[0] + a[n * 2 - 1]; + for i := 1 to n - 1 do + begin + tmp := a[i] + a[n * 2 - i - 1]; + if tmp > max then + max := tmp + end; + writeln(max) +end. diff --git a/others/volume1/096.pas b/others/volume1/096.pas index 4cb877c..b204835 100644 --- a/others/volume1/096.pas +++ b/others/volume1/096.pas @@ -1,34 +1,10 @@ -uses math, strutils; +uses clib; var a, b: ansistring; - n: int16; - remain: boolean = false; - d: uint8; begin readln(a); readln(b); - n := max(length(a), length(b)) + 1; - a := addchar('0', a, n); - b := addchar('0', b, n); - repeat - if remain then - d := ord(a[n]) + ord(b[n]) - 47 - else - d := ord(a[n]) + ord(b[n]) - 48; - if d > 57 then - begin - dec(d, 10); - remain := true - end - else - remain := false; - a[n] := chr(d); - dec(n) - until n = 0; - if ord(a[1]) = 48 then - writeln(copy(a, 2, length(a) - 1)) - else - writeln(a) + writeln(addintstr(a, b)) end. diff --git a/others/volume1/124.pas b/others/volume1/124.pas new file mode 100644 index 0000000..6a41c8e --- /dev/null +++ b/others/volume1/124.pas @@ -0,0 +1,28 @@ +uses clib; + +var + m, n, i, k: int8; + a: intar; + s: array of array of ansistring; + +begin + readln(n, k); + setlength(a, n); + for i := 0 to n - 1 do + read(a[i]); + qsort(a); + m := 1; + for i := 1 to n - 1 do + if a[i] > a[i - 1] then + inc(m); + setlength(s, m); + for n := 0 to m - 1 do + begin + setlength(s[n], n + 2); + s[n][0] := '1'; + for i := 1 to n do + s[n][i] := addintstr(s[n - 1][i], s[n - 1][i - 1]); + s[n][n + 1] := '0' + end; + writeln(addintstr(s[m - 1][k], s[m - 1][k - 1])) +end. diff --git a/others/volume1/clib.pas b/others/volume1/clib.pas index b9037cd..ee74243 100644 --- a/others/volume1/clib.pas +++ b/others/volume1/clib.pas @@ -3,6 +3,8 @@ unit clib; interface + uses math, strutils; + type intar = array of int64; @@ -130,6 +132,7 @@ interface function issquare(x: int64): boolean; function ispalindrome(s: ansistring): boolean; function all(b: array of boolean): boolean; + function addintstr(a, b: ansistring): ansistring; procedure qsort(var a : intar); function bsearch( @@ -236,6 +239,35 @@ implementation end; + function addintstr(a, b: ansistring): ansistring; + var + n: int64; + remain: boolean = false; + d: uint8; + + begin + n := max(length(a), length(b)) + 1; + a := addchar('0', a, n); + b := addchar('0', b, n); + repeat + if remain then + d := ord(a[n]) + ord(b[n]) - 47 + else + d := ord(a[n]) + ord(b[n]) - 48; + if d > 57 then + begin + dec(d, 10); + remain := true + end + else + remain := false; + a[n] := chr(d); + dec(n) + until n = 0; + addintstr := ifthen(ord(a[1]) = 48, copy(a, 2, length(a) - 1), a) + end; + + function bsearch( a: intar; x: int64 |