diff --git a/Canon.Tests/SemanticTests/Tests.cs b/Canon.Tests/SemanticTests/Tests.cs new file mode 100644 index 0000000..4bf8cf3 --- /dev/null +++ b/Canon.Tests/SemanticTests/Tests.cs @@ -0,0 +1,59 @@ +using Canon.Core.SemanticParser; +using Canon.Core.SyntaxNodes; +using Canon.Tests.Utils; +using Xunit.Abstractions; + +namespace Canon.Tests.SemanticTests; + +public class Tests(ITestOutputHelper helper) +{ + [Fact] + public void Test() + { + const string program = """ + program main; + + var + x, y: array[0..0] of integer; + a, b: integer; + + function exgcd(a, b: integer; var x, y: integer): integer; + var + t, r: integer; + begin + if b = 0 then + begin + x := 1; + y := 0; + exgcd := a; + end + else + begin + r := exgcd(b, a mod b, x, y); + t := x; + x := y; + y := (t - (a div b) * y); + exgcd := r; + end; + end; + + begin + a := 7; + b := 15; + x[0] := 1; + y[0] := 1; + exgcd(a, b, x[0], y[0]); + x[0] := ((x[0] mod b) + b) mod b; + write(x[0]); + end. + """; + + ProgramStruct root = CompilerHelpers.Analyse(program); + SyntaxTreeTraveller traveller = new(); + + CodeGeneratorVisitor visitor = new(); + traveller.Travel(root, visitor); + + helper.WriteLine(visitor.Builder.Build()); + } +} diff --git a/open_set/70_comment2.pas b/open_set/70_comment2.pas new file mode 100644 index 0000000..a9db183 --- /dev/null +++ b/open_set/70_comment2.pas @@ -0,0 +1,10 @@ +// skipher +// int main(){ +program main; +begin + { ret := 0; + ret := 1; + ret := 2; + } + write(3); +end. diff --git a/open_set/71_multiple_returns.pas b/open_set/71_multiple_returns.pas new file mode 100644 index 0000000..84a4cfc --- /dev/null +++ b/open_set/71_multiple_returns.pas @@ -0,0 +1,13 @@ +program main; +const + AA = 4; +var + a, b, c, d: integer; +begin + b := 8; + c := 12; + a := b + c; + d := 9; + a := (AA - b) * c; + write(a); +end. diff --git a/open_set/72_branch.pas b/open_set/72_branch.pas new file mode 100644 index 0000000..9268e4d --- /dev/null +++ b/open_set/72_branch.pas @@ -0,0 +1,59 @@ +program main; +var + ret, a, b, c, d, e, f: integer; +begin + ret := 0; + a := 1; + b := 2; + c := 3; + d := 4; + e := 5; + f := 6; + + if (a * b + c < 6) and (d <> 0) then + begin + if (e <> 0) or (not(a + 0 <> 0)) then + begin + if (c = 2) and (d + e > 2) then + ret := 3 + else + begin + if (f mod c <> 0) and (e <> 0) then + ret := 4 + else + begin + if (d div b + a >= 2) then + begin + if (e - f >= 0) or (d > 4) then + ret := 6 + else + begin + if (c <> f) then + begin + if (b + e * d > 10) then + begin + if (f = 0) then + ret := 9 + else + ret := 10; + end + else + ret := 8; + end + else + ret := 7; + end; + end + else + ret := 5; + end; + end; + end + else + ret := 2; + end + else + ret := 1; + + write(ret); +end. diff --git a/open_set/73_param_name.pas b/open_set/73_param_name.pas new file mode 100644 index 0000000..8e399bd --- /dev/null +++ b/open_set/73_param_name.pas @@ -0,0 +1,13 @@ +program main; +var ret:integer; + +function Fn(f: integer): integer; +begin + Fn := f * 2; +end; + +begin + ret := 0; + ret := Fn(10); + write(ret); +end. diff --git a/open_set/74_func_name.pas b/open_set/74_func_name.pas new file mode 100644 index 0000000..bba9636 --- /dev/null +++ b/open_set/74_func_name.pas @@ -0,0 +1,13 @@ +program main; +var ret, f: integer; +function fn:integer; +begin + fn := 10; +end; + +begin + ret := 0; + f := 20; + ret := f; + write(ret); +end. diff --git a/open_set/75_arr_init_nd.pas b/open_set/75_arr_init_nd.pas new file mode 100644 index 0000000..f393e73 --- /dev/null +++ b/open_set/75_arr_init_nd.pas @@ -0,0 +1,146 @@ +program main; +var + ret: integer; + a: array[1..5, 1..3] of integer; + b: array[1..5, 1..3] of integer; + c: array[1..5, 1..3] of integer; + d: array[1..5, 1..3] of integer; + e: array[1..5, 1..3] of integer; + f: array[1..5] of integer; + g: array[1..5, 1..3] of integer; + h: array[1..3] of integer; + i: array[1..2, 1..3, 1..4] of integer; +begin + ret := 0; + + a[1, 1] := 0; + a[1, 2] := 0; + a[1, 3] := 0; + a[2, 1] := 0; + a[2, 2] := 0; + a[2, 3] := 0; + a[3, 1] := 0; + a[3, 2] := 0; + a[3, 3] := 0; + a[4, 1] := 0; + a[4, 2] := 0; + a[4, 3] := 0; + a[5, 1] := 0; + a[5, 2] := 0; + a[5, 3] := 0; + + b[1, 1] := 0; + b[1, 2] := 0; + b[1, 3] := 0; + b[2, 1] := 0; + b[2, 2] := 0; + b[2, 3] := 0; + b[3, 1] := 0; + b[3, 2] := 0; + b[3, 3] := 0; + b[4, 1] := 0; + b[4, 2] := 0; + b[4, 3] := 0; + b[5, 1] := 0; + b[5, 2] := 0; + b[5, 3] := 0; + + c[1, 1] := 1; + c[1, 2] := 2; + c[1, 3] := 3; + c[2, 1] := 4; + c[2, 2] := 5; + c[2, 3] := 6; + c[3, 1] := 7; + c[3, 2] := 8; + c[3, 3] := 9; + c[4, 1] := 10; + c[4, 2] := 11; + c[4, 3] := 12; + c[5, 1] := 13; + c[5, 2] := 14; + c[5, 3] := 15; + + d[1, 1] := 1; + d[1, 2] := 2; + d[1, 3] := 3; + d[2, 1] := 4; + d[2, 2] := 5; + d[2, 3] := 6; + d[3, 1] := 7; + d[3, 2] := 8; + d[3, 3] := 9; + d[4, 1] := 10; + d[4, 2] := 11; + d[4, 3] := 12; + d[5, 1] := 13; + d[5, 2] := 14; + d[5, 3] := 15; + + e[1, 1] := 1; + e[1, 2] := 2; + e[1, 3] := 3; + e[2, 1] := 4; + e[2, 2] := 5; + e[2, 3] := 6; + e[3, 1] := 7; + e[3, 2] := 8; + e[3, 3] := 9; + e[4, 1] := 10; + e[4, 2] := 11; + e[4, 3] := 12; + e[5, 1] := 13; + e[5, 2] := 14; + e[5, 3] := 15; + + f[1] := 0; + f[2] := 0; + f[3] := 0; + f[4] := 0; + f[5] := 0; + + g[1, 1] := 1; + g[1, 2] := 2; + g[1, 3] := 3; + g[2, 1] := 4; + g[2, 2] := 0; + g[2, 3] := 0; + g[3, 1] := 7; + g[3, 2] := 0; + g[3, 3] := 0; + g[4, 1] := 10; + g[4, 2] := 11; + g[4, 3] := 12; + g[5, 1] := 0; + g[5, 2] := 0; + g[5, 3] := 0; + + h[1] := 0; + h[2] := 0; + h[3] := 0; + + i[1, 1, 1] := 1; + i[1, 1, 2] := 2; + i[1, 1, 3] := 3; + i[1, 1, 4] := 4; + i[1, 2, 1] := 5; + i[1, 2, 2] := 0; + i[1, 2, 3] := 0; + i[1, 2, 4] := 0; + i[2, 1, 1] := 0; + i[2, 1, 2] := 0; + i[2, 1, 3] := 0; + i[2, 1, 4] := 0; + i[2, 2, 1] := 0; + i[2, 2, 2] := 0; + i[2, 2, 3] := 0; + i[2, 2, 4] := 0; + i[2, 3, 1] := 0; + i[2, 3, 2] := 0; + i[2, 3, 3] := 0; + i[2, 3, 4] := 0; + + ret := 4; + + write(ret); +end. diff --git a/open_set/76_global_arr_init.pas b/open_set/76_global_arr_init.pas new file mode 100644 index 0000000..5b20ff2 --- /dev/null +++ b/open_set/76_global_arr_init.pas @@ -0,0 +1,89 @@ +program main; +var + ret: integer; + a0: array[0..2] of integer; + b0: array[0..3] of integer; + c0: array[0..6] of integer; + c: array[0..4, 0..2] of integer; + d: array[0..4, 0..2] of integer; + e: array[0..4, 0..2] of integer; + +procedure InitializeArrays; +begin + // Initialize arrays a0, b0, and c0 element by element + a0[0] := 0; + a0[1] := 0; + a0[2] := 0; + + b0[0] := 0; + b0[1] := 1; + b0[2] := 0; + b0[3] := 0; + + c0[0] := 2; + c0[1] := 8; + c0[2] := 6; + c0[3] := 3; + c0[4] := 9; + c0[5] := 1; + c0[6] := 5; + + // Initialize arrays c, d, and e element by element + c[0, 0] := 1; + c[0, 1] := 2; + c[0, 2] := 3; + c[1, 0] := 4; + c[1, 1] := 5; + c[1, 2] := 6; + c[2, 0] := 7; + c[2, 1] := 8; + c[2, 2] := 9; + c[3, 0] := 10; + c[3, 1] := 11; + c[3, 2] := 12; + c[4, 0] := 13; + c[4, 1] := 14; + c[4, 2] := 15; + + d[0, 0] := 1; + d[0, 1] := 2; + d[0, 2] := 3; + d[1, 0] := 4; + d[1, 1] := 5; + d[1, 2] := 6; + d[2, 0] := 7; + d[2, 1] := 8; + d[2, 2] := 9; + d[3, 0] := 10; + d[3, 1] := 11; + d[3, 2] := 12; + d[4, 0] := 13; + d[4, 1] := 14; + d[4, 2] := 15; + + e[0, 0] := 1; + e[0, 1] := 2; + e[0, 2] := 3; + e[1, 0] := 4; + e[1, 1] := 5; + e[1, 2] := 6; + e[2, 0] := 7; + e[2, 1] := 8; + e[2, 2] := 9; + e[3, 0] := 10; + e[3, 1] := 11; + e[3, 2] := 12; + e[4, 0] := 13; + e[4, 1] := 14; + e[4, 2] := 15; +end; + +begin + ret := 0; + + InitializeArrays; + + ret := 5; + + write(ret); +end. diff --git a/open_set/77_BST.in b/open_set/77_BST.in new file mode 100644 index 0000000..00ccc5e --- /dev/null +++ b/open_set/77_BST.in @@ -0,0 +1,123 @@ +100 +88 +10 +65 +34 +3 +69 +54 +14 +96 +35 +76 +0 +59 +12 +4 +94 +91 +67 +40 +44 +61 +30 +92 +46 +62 +98 +22 +22 +47 +15 +14 +82 +34 +91 +85 +18 +80 +77 +35 +18 +50 +4 +56 +45 +78 +48 +73 +94 +80 +45 +50 +1 +74 +79 +96 +60 +51 +35 +42 +92 +88 +99 +82 +98 +99 +13 +9 +79 +68 +61 +92 +79 +87 +79 +41 +61 +54 +74 +11 +63 +11 +60 +78 +16 +4 +55 +22 +19 +90 +9 +72 +48 +25 +90 +96 +25 +85 +63 +34 +66 + +20 +35 +91 +24 +57 +3 +14 +56 +91 +83 +37 +38 +80 +55 +63 +53 +62 +57 +71 +20 +49 diff --git a/open_set/77_BST.pas b/open_set/77_BST.pas new file mode 100644 index 0000000..0d08744 --- /dev/null +++ b/open_set/77_BST.pas @@ -0,0 +1,143 @@ +program BinarySearchTree; + +var + value: array[0..9999] of integer; + left_child: array[0..9999] of integer; + right_child: array[0..9999] of integer; + now: integer; + ret, n, readN, i, root: integer; + +function search(root, x: integer): integer; +begin + if (root = -1) or (value[root] = x) then + search := root + else + begin + if (x > value[root]) then + search := search(right_child[root], x) + else + search := search(left_child[root], x); + end; +end; + +function find_minimum(root: integer): integer; +begin + if (root = -1) then + find_minimum := -1 + else + begin + if (left_child[root] <> -1) then + find_minimum := find_minimum(left_child[root]) + else + find_minimum := root; + end; +end; + +function new_node(x: integer): integer; +begin + value[now] := x; + left_child[now] := -1; + right_child[now] := -1; + new_node := now; + now := now + 1; +end; + +function insert(root, x: integer): integer; +begin + if (root = -1) then + insert := new_node(x) + else + begin + if (x > value[root]) then + right_child[root] := insert(right_child[root], x) + else + left_child[root] := insert(left_child[root], x); + end; + insert := root; +end; + +function delete_node(root, x: integer): integer; +var + tmp: integer; +begin + if (x > value[root]) then +begin + right_child[root] := delete_node(right_child[root], x); +end +else +begin + if (x < value[root]) then + begin + left_child[root] := delete_node(left_child[root], x); + end + else + begin + if (left_child[root] = -1) and (right_child[root] = -1) then + begin + delete_node := -1; + end + else + begin + if (left_child[root] = -1) or (right_child[root] = -1) then + begin + if (left_child[root] = -1) then + begin + delete_node := right_child[root]; + end + else + begin + delete_node := left_child[root]; + end; + end + else + begin + tmp := find_minimum(right_child[root]); + value[root] := value[tmp]; + right_child[root] := delete_node(right_child[root], value[tmp]); + end; + end; + end; +end; + delete_node := root; +end; + +procedure inorder(root: integer); +begin + if (root <> -1) then + begin + inorder(left_child[root]); + write(value[root], ' '); + inorder(right_child[root]); + end; +end; + + + +begin + ret := 0; + now := 0; + + read(n); + if (n = 0) then + ret := 0; + + read(readN); + root := new_node(readN); + + for i := 1 to n - 1 do + begin + read(readN); + insert(root, readN); + end; + + inorder(root); + + read(n); + for i := 1 to n do + begin + read(readN); + root := delete_node(root, readN); + end; + + inorder(root); +end. diff --git a/open_set/78_dp.in b/open_set/78_dp.in new file mode 100644 index 0000000..f132ebd --- /dev/null +++ b/open_set/78_dp.in @@ -0,0 +1,8 @@ +7 2 +2 +1 +1 +2 +2 +1 +1 \ No newline at end of file diff --git a/open_set/78_dp.pas b/open_set/78_dp.pas new file mode 100644 index 0000000..fefc47b --- /dev/null +++ b/open_set/78_dp.pas @@ -0,0 +1,58 @@ +program main; + +var + t: array[0..1004, 0..1] of integer; + dp: array[0..1004, 0..34] of integer; + TT, W, x, i, j, res: integer; + +function getint: integer; +var + n: integer; +begin + read(n); + getint := n; +end; + +begin + for i := 0 to 1004 do + begin + t[i, 0] := 0; + t[i, 1] := 0; + for j := 0 to 34 do + dp[i, j] := 0; + end; + + TT := getint(); + W := getint(); + for i := 1 to TT do + begin + x := getint(); + t[i, x mod 2] := 1; + dp[i, 0] := dp[i - 1, 0] + t[i, 1]; + end; + + for i := 1 to TT do + begin + for j := 1 to W do + begin + if (dp[i - 1, j] + t[i, (j + 1) mod 2] > dp[i - 1, j - 1] + t[i, (j + 1) mod 2]) then + begin + dp[i, j] := dp[i - 1, j] + t[i, (j + 1) mod 2]; + end + else + begin + dp[i, j] := dp[i - 1, j - 1] + t[i, (j + 1) mod 2]; + end; + end; + end; + + res := 0; + for j := 0 to W do + begin + if res < dp[TT, j] then + begin + res := dp[TT, j]; + end; + end; + write(res); +end. diff --git a/open_set/79_graph_coloring.pas b/open_set/79_graph_coloring.pas new file mode 100644 index 0000000..fe0dfcf --- /dev/null +++ b/open_set/79_graph_coloring.pas @@ -0,0 +1,91 @@ +program main; +const +space = 32; +ne = 'Not exist'; +var +graph: array[0..3, 0..3] of integer; +color: array[0..3] of integer; +i, m: integer; + +procedure printSolution(); +var i: integer; +begin + for i := 0 to 3 do + write(color[i]); +end; + +procedure printMessage(); +begin + write(ne); +end; + +function isSafe():integer; +var i,j: integer; +begin + isSafe := 1; + for i := 0 to 3 do + for j := i + 1 to 3 do + if (graph[i, j] <> 0) and (color[j] = color[i]) then + isSafe := 0; +end; + +function graphColoring(m, i: integer): integer; +var + j: integer; + foundSolution: boolean; +begin + foundSolution := false; + + if (i = 4) then + begin + if (isSafe() <> 0) then + begin + printSolution(); + graphColoring := 1; + foundSolution := True; + end; + end + else + begin + for j := 1 to m do + begin + color[i] := j; + if (graphColoring(m, i + 1) <> 0) then + begin + foundSolution := True; + Break; + end; + color[i] := 0; + end; + end; + + if foundSolution then + graphColoring := 1 + else + graphColoring := 0; +end; + + +begin + graph[0, 0] := 0; + graph[0, 1] := 1; + graph[0, 2] := 1; + graph[0, 3] := 1; + graph[1, 0] := 1; + graph[1, 1] := 0; + graph[1, 2] := 1; + graph[1, 3] := 0; + graph[2, 0] := 1; + graph[2, 1] := 1; + graph[2, 2] := 0; + graph[2, 3] := 1; + graph[3, 0] := 1; + graph[3, 1] := 0; + graph[3, 2] := 1; + graph[3, 3] := 0; + m := 3; + for i := 0 to 3 do + color[i] := 0; + if graphColoring(m, 0) = 0 then + printMessage; +end. diff --git a/open_set/80_k_smallest.in b/open_set/80_k_smallest.in new file mode 100644 index 0000000..b7bb357 --- /dev/null +++ b/open_set/80_k_smallest.in @@ -0,0 +1,2 @@ +12 5 +11 3 2 1 15 5 4 45 88 96 50 45 \ No newline at end of file diff --git a/open_set/80_k_smallest.pas b/open_set/80_k_smallest.pas new file mode 100644 index 0000000..dab23d2 --- /dev/null +++ b/open_set/80_k_smallest.pas @@ -0,0 +1,84 @@ +program FindSmallest; + +const + space = 32; + +var + arr: array[0..999] of integer; + n, k, i, low, high: integer; + +procedure swap(a, b: integer); +var + tmp: integer; +begin + tmp := arr[a]; + arr[a] := arr[b]; + arr[b] := tmp; +end; + +function findPivot(start, endIndex: integer): integer; +var + pivot, pIndex, i: integer; +begin + pivot := arr[endIndex]; + pIndex := start; + + for i := start to endIndex - 1 do + begin + if arr[i] <= pivot then + begin + swap(i, pIndex); + pIndex := pIndex + 1; + end; + end; + swap(pIndex, endIndex); + findPivot := pIndex; +end; + +procedure findSmallest(low, high, k, n: integer); +var + pIndex, i: integer; +begin + if low <> high then + begin + pIndex := findPivot(low, high); + if k = pIndex then + begin + for i := 0 to pIndex - 1 do + begin + write(arr[i]); + end; + end + else if k < pIndex then + begin + findSmallest(low, pIndex - 1, k, n); + end + else + begin + findSmallest(pIndex + 1, high, k, n); + end; + end; +end; + +function getint: integer; +var + n: integer; +begin + read(n); + getint := n; +end; + +begin + n := getint; + k := getint; + + for i := 0 to n - 1 do + begin + arr[i] := getint; + end; + + low := 0; + high := n - 1; + + findSmallest(low, high, k, n); +end. diff --git a/open_set/81_maximal_clique.in b/open_set/81_maximal_clique.in new file mode 100644 index 0000000..ee96652 --- /dev/null +++ b/open_set/81_maximal_clique.in @@ -0,0 +1,28 @@ +20 27 +13 5 +3 18 +3 20 +11 1 +5 14 +7 9 +20 19 +13 16 +12 20 +7 5 +18 2 +11 14 +11 6 +1 13 +1 10 +3 17 +3 1 +8 12 +12 20 +9 2 +6 10 +19 15 +18 11 +19 12 +6 20 +18 2 +20 16 diff --git a/open_set/81_maximal_clique.pas b/open_set/81_maximal_clique.pas new file mode 100644 index 0000000..3778c78 --- /dev/null +++ b/open_set/81_maximal_clique.pas @@ -0,0 +1,60 @@ +program MaxClique; + +var + store: array[0..29] of integer; + n, m: integer; + graph: array[0..29, 0..29] of integer; + edges: array[0..599, 0..1] of integer; + i, ret: integer; + +function is_clique(num: integer): integer; +var + i, j: integer; +begin + is_clique := 1; + for i := 1 to num - 1 do + begin + for j := i + 1 to num - 1 do + begin + if graph[store[i], store[j]] = 0 then + is_clique := 0; + end; + end; +end; + +function maxCliques(i, k: integer): integer; +var + max_, j, tmp: integer; +begin + max_ := 0; + for j := 1 to n do + begin + store[k] := j; + if is_clique(k + 1) <> 0 then + begin + if k > max_ then + max_ := k; + tmp := maxCliques(j, k + 1); + if tmp > max_ then + max_ := tmp; + end; + end; + maxCliques := max_; +end; + +begin + read(n); + read(m); + for i := 0 to m - 1 do + begin + read(edges[i, 0]); + read(edges[i, 1]); + end; + for i := 0 to m - 1 do + begin + graph[edges[i, 0], edges[i, 1]] := 1; + graph[edges[i, 1], edges[i, 0]] := 1; + end; + ret := maxCliques(0, 1); + write(ret); +end. diff --git a/open_set/82_prim.in b/open_set/82_prim.in new file mode 100644 index 0000000..528bf7b --- /dev/null +++ b/open_set/82_prim.in @@ -0,0 +1,1001 @@ +100 1000 +29 80 330 +4 70 528 +69 61 694 +40 14 648 +15 56 766 +17 92 83 +74 53 396 +88 29 211 +3 13 152 +10 68 719 +62 91 213 +20 94 491 +59 67 116 +2 22 343 +78 50 352 +50 58 514 +40 78 354 +80 74 629 +75 96 695 +90 89 824 +97 42 832 +5 41 934 +17 93 631 +15 15 417 +20 47 872 +66 76 576 +79 18 330 +41 36 628 +33 31 513 +9 92 606 +69 20 42 +60 80 910 +85 24 681 +91 28 811 +61 13 632 +24 99 63 +44 35 371 +51 77 246 +11 91 637 +26 86 772 +41 33 252 +29 91 566 +67 39 560 +86 15 605 +90 64 59 +14 50 902 +54 40 993 +86 77 447 +18 70 994 +78 92 586 +72 77 260 +66 83 421 +38 4 527 +85 36 899 +97 95 202 +4 97 402 +97 43 967 +63 91 840 +68 42 915 +14 100 699 +7 14 733 +42 88 510 +19 54 415 +94 44 643 +84 15 222 +14 33 689 +36 65 71 +90 15 375 +12 38 457 +100 96 812 +88 96 263 +69 8 652 +14 10 4 +22 80 646 +94 98 54 +36 80 262 +65 100 745 +26 37 621 +47 52 48 +52 24 562 +37 77 906 +95 82 431 +52 14 883 +32 99 430 +43 8 306 +80 4 79 +51 33 896 +66 97 592 +47 47 414 +57 58 533 +58 73 876 +95 9 924 +91 41 291 +83 56 170 +41 37 679 +27 87 642 +64 64 409 +60 81 923 +43 49 827 +89 13 248 +35 44 503 +51 65 643 +71 28 977 +19 88 156 +89 68 368 +96 33 262 +23 55 968 +25 29 429 +18 35 910 +54 56 812 +76 69 502 +92 30 907 +5 11 205 +8 50 587 +40 59 403 +22 73 164 +39 69 578 +10 87 736 +61 93 555 +23 31 48 +61 68 213 +1 43 704 +55 34 964 +34 65 840 +7 27 4 +69 12 754 +88 97 569 +69 18 563 +69 16 706 +98 95 527 +42 2 301 +33 14 177 +46 75 383 +97 79 245 +57 35 523 +90 33 107 +2 94 920 +47 11 976 +45 70 228 +33 71 907 +100 78 289 +19 59 195 +91 66 378 +91 15 977 +28 47 242 +13 37 198 +100 4 317 +62 78 534 +2 20 679 +98 100 616 +69 21 523 +9 1 517 +92 45 676 +94 68 655 +37 25 516 +9 50 510 +5 5 688 +32 11 766 +4 23 93 +45 31 276 +6 46 656 +12 29 310 +4 70 12 +94 41 722 +67 71 895 +89 80 528 +2 22 845 +32 39 475 +97 13 708 +52 70 371 +34 11 117 +64 17 559 +52 85 12 +37 45 362 +34 13 900 +7 51 253 +56 97 752 +17 43 968 +75 82 935 +98 57 285 +65 40 873 +65 74 566 +13 16 110 +31 97 28 +2 51 426 +57 86 251 +98 18 754 +87 12 134 +80 22 319 +39 91 886 +97 25 227 +16 44 336 +59 99 116 +69 61 337 +47 6 137 +28 22 812 +73 89 768 +16 18 814 +25 87 392 +75 59 513 +51 12 627 +3 57 823 +100 22 32 +82 52 618 +29 27 901 +56 88 313 +42 29 565 +6 63 662 +36 70 944 +13 59 89 +54 99 227 +68 22 760 +43 30 888 +30 82 73 +59 70 670 +100 63 224 +86 22 633 +85 78 381 +40 58 257 +55 97 442 +53 43 800 +54 66 434 +2 40 452 +84 57 277 +12 82 486 +85 100 230 +61 71 434 +24 21 207 +89 33 426 +29 90 526 +40 15 883 +50 92 855 +79 80 654 +71 54 196 +4 51 959 +4 27 380 +11 93 405 +90 42 688 +83 98 836 +94 30 813 +57 38 642 +41 46 313 +38 68 281 +2 54 368 +8 65 843 +10 76 803 +67 99 986 +6 93 567 +76 29 7 +31 53 419 +80 31 950 +63 63 296 +58 12 197 +43 97 138 +16 61 751 +27 24 84 +18 36 478 +26 18 335 +55 99 17 +52 39 730 +65 58 221 +45 4 264 +21 87 470 +65 62 421 +98 32 5 +49 31 682 +50 23 305 +40 62 740 +62 86 739 +54 72 535 +17 88 681 +85 16 65 +69 76 214 +87 85 880 +37 46 767 +54 40 885 +16 10 19 +24 20 59 +27 10 883 +8 37 129 +9 72 341 +23 14 303 +77 98 187 +50 97 392 +57 24 36 +67 52 598 +99 2 308 +27 23 956 +68 65 580 +5 78 555 +45 64 654 +77 11 38 +32 65 664 +84 11 572 +37 69 114 +35 45 42 +27 57 744 +72 57 425 +21 68 830 +23 17 427 +35 59 745 +94 54 542 +67 31 804 +33 74 459 +3 21 803 +62 22 358 +39 92 15 +67 32 382 +80 41 464 +89 89 785 +22 1 920 +10 30 503 +87 21 203 +8 27 456 +69 27 367 +44 28 723 +94 56 6 +89 47 590 +35 41 348 +10 14 78 +90 76 895 +85 42 585 +59 16 463 +91 45 922 +47 73 965 +93 13 794 +20 55 974 +18 2 303 +58 2 15 +65 28 665 +79 23 879 +46 53 232 +65 80 957 +86 43 573 +83 11 414 +100 7 555 +52 12 403 +16 97 267 +14 77 937 +9 22 531 +27 17 546 +84 5 333 +63 60 625 +52 29 729 +57 41 8 +15 18 629 +6 27 314 +96 83 649 +64 67 722 +2 78 299 +40 4 62 +43 43 545 +12 37 1 +11 28 75 +4 77 686 +7 82 703 +13 83 26 +53 80 522 +94 27 714 +73 16 932 +83 52 433 +96 100 363 +26 37 683 +55 1 316 +44 64 304 +76 5 829 +43 72 454 +21 39 288 +14 86 244 +86 80 456 +40 11 331 +4 7 606 +42 47 632 +26 30 695 +23 29 798 +54 73 294 +60 99 414 +55 41 528 +49 80 437 +52 30 129 +19 66 498 +1 80 779 +22 85 146 +62 12 438 +3 22 856 +78 21 768 +66 10 146 +59 69 837 +58 79 144 +11 37 916 +14 27 735 +40 88 176 +67 23 0 +84 60 37 +15 92 594 +24 61 670 +49 47 482 +37 50 988 +88 14 605 +40 14 346 +24 11 943 +23 66 259 +75 77 351 +36 82 708 +60 54 252 +95 73 272 +6 13 208 +36 58 439 +46 25 691 +21 81 952 +38 76 495 +79 37 419 +63 8 804 +44 38 495 +20 26 265 +14 76 588 +98 60 661 +28 97 664 +71 55 92 +77 22 307 +26 56 79 +16 80 848 +29 50 940 +96 5 731 +41 26 722 +29 53 696 +6 50 85 +47 6 351 +43 75 507 +47 35 68 +85 61 49 +5 65 170 +86 22 124 +64 14 341 +53 98 36 +9 16 8 +37 11 628 +2 57 102 +72 4 358 +66 32 315 +66 15 120 +56 45 653 +89 45 440 +70 77 145 +85 2 809 +87 80 784 +31 65 122 +89 40 972 +38 58 231 +85 27 251 +64 19 355 +12 94 2 +54 30 215 +75 52 295 +84 19 737 +91 43 510 +9 10 688 +49 23 141 +39 45 747 +46 75 15 +11 45 163 +46 92 259 +100 30 709 +76 39 344 +77 51 954 +56 9 551 +87 76 779 +55 12 40 +49 41 145 +24 48 634 +44 86 24 +80 64 59 +41 34 829 +17 43 479 +98 25 737 +3 25 992 +96 68 73 +55 46 692 +51 29 853 +78 99 550 +30 10 624 +26 81 577 +29 24 119 +39 72 569 +57 98 703 +69 11 407 +12 80 967 +50 30 105 +76 18 529 +9 38 962 +65 19 524 +63 12 917 +87 72 625 +6 1 163 +87 59 470 +49 9 436 +72 100 451 +100 67 599 +36 14 323 +94 10 636 +93 49 347 +40 20 188 +11 100 719 +59 73 255 +94 42 721 +12 73 998 +72 27 809 +87 62 251 +24 9 156 +72 52 605 +68 70 866 +85 33 265 +54 52 510 +7 17 946 +29 61 225 +92 48 561 +75 72 552 +74 19 977 +52 36 45 +41 11 91 +53 63 959 +92 30 241 +13 19 249 +36 98 609 +29 81 230 +98 17 714 +68 77 262 +64 30 228 +19 98 637 +75 95 919 +38 24 836 +39 86 533 +16 19 10 +91 67 29 +54 44 690 +53 67 470 +53 66 14 +96 64 802 +28 2 128 +18 99 40 +22 13 242 +57 61 82 +98 28 842 +50 74 510 +58 13 570 +99 28 686 +73 98 863 +26 19 825 +1 79 234 +29 57 670 +63 47 51 +37 89 29 +16 20 928 +92 91 617 +91 1 569 +20 48 781 +12 87 546 +94 10 98 +89 5 980 +33 78 491 +35 44 617 +46 99 734 +71 62 534 +56 89 227 +54 22 533 +84 51 291 +11 40 153 +59 7 720 +14 30 466 +6 72 811 +98 80 590 +49 56 311 +88 81 210 +31 46 90 +52 35 892 +26 43 124 +63 57 564 +91 98 917 +50 75 580 +57 80 578 +46 96 149 +11 13 92 +32 29 873 +84 84 623 +50 98 6 +57 8 449 +19 28 92 +99 82 414 +1 80 533 +31 26 66 +58 21 256 +76 49 135 +7 99 807 +57 77 291 +64 20 290 +74 66 581 +28 74 317 +96 85 984 +54 34 597 +10 72 471 +14 64 686 +97 85 898 +22 24 676 +26 53 617 +49 65 102 +45 95 239 +3 83 401 +67 11 164 +56 79 564 +19 39 783 +90 73 37 +21 35 331 +42 83 89 +59 87 957 +80 26 600 +72 1 864 +38 73 535 +48 98 195 +25 6 939 +13 56 95 +75 68 79 +77 54 546 +81 27 227 +53 28 129 +91 26 167 +71 22 96 +85 35 327 +74 5 292 +81 76 851 +63 24 58 +81 64 245 +12 30 168 +52 53 754 +6 79 261 +20 78 218 +83 51 342 +78 65 188 +20 68 240 +19 16 24 +38 39 669 +30 40 650 +69 90 149 +70 46 788 +82 20 197 +6 79 77 +78 59 688 +83 34 591 +59 3 424 +68 16 939 +9 5 30 +53 78 420 +26 31 6 +38 13 767 +99 97 106 +89 46 764 +1 14 48 +15 19 200 +97 22 444 +18 81 758 +98 95 423 +5 12 388 +24 6 107 +18 89 57 +51 34 710 +36 24 902 +16 97 589 +87 54 470 +46 41 165 +37 27 365 +72 9 285 +64 74 849 +44 37 592 +43 35 517 +76 25 973 +9 23 504 +92 76 656 +77 8 299 +39 52 276 +17 46 407 +19 66 888 +33 100 420 +67 33 154 +54 28 434 +26 34 395 +79 16 879 +98 37 258 +41 29 707 +58 31 524 +8 2 492 +62 61 655 +54 39 277 +44 27 567 +17 77 811 +83 41 594 +55 60 498 +82 23 207 +11 63 833 +28 8 131 +68 8 506 +33 55 671 +41 18 224 +16 69 670 +94 18 4 +31 7 404 +29 21 870 +90 2 937 +77 76 673 +59 14 483 +11 11 865 +79 67 427 +82 4 646 +59 27 896 +59 64 256 +94 50 327 +93 17 762 +89 98 343 +4 3 317 +5 32 82 +26 18 704 +9 88 567 +69 36 401 +39 83 305 +35 70 6 +99 97 451 +83 20 695 +77 54 391 +38 55 535 +32 89 219 +20 58 869 +25 8 853 +83 36 285 +14 93 739 +27 16 55 +100 82 331 +92 98 586 +16 65 258 +88 89 493 +44 18 279 +80 14 208 +87 15 287 +21 8 48 +34 84 948 +9 81 110 +62 1 463 +45 45 505 +52 47 29 +82 43 542 +87 25 298 +11 10 450 +53 20 138 +92 8 68 +11 12 471 +67 45 368 +87 27 762 +75 100 345 +10 6 868 +58 37 543 +74 13 314 +79 37 568 +43 81 523 +79 30 336 +40 25 53 +64 43 119 +91 92 82 +82 85 72 +74 54 844 +76 91 194 +96 49 986 +58 32 714 +85 89 497 +11 87 372 +64 62 811 +1 2 584 +71 95 591 +55 38 871 +54 64 126 +56 10 533 +42 85 836 +5 47 29 +13 21 771 +12 93 109 +37 47 322 +50 55 918 +59 19 444 +9 84 608 +11 94 650 +35 71 652 +47 85 674 +47 71 788 +42 66 746 +84 30 805 +90 94 878 +9 31 411 +53 11 513 +55 71 441 +83 60 243 +46 71 652 +83 74 497 +52 66 164 +70 85 707 +45 37 173 +77 98 109 +2 21 781 +6 75 328 +38 14 136 +90 36 212 +8 61 735 +66 73 100 +66 96 789 +91 80 276 +97 9 599 +81 94 106 +10 50 984 +54 73 938 +74 35 575 +24 78 143 +35 42 187 +67 80 153 +23 57 337 +37 42 860 +80 50 558 +11 4 785 +20 82 655 +25 16 494 +65 76 277 +27 81 811 +7 5 338 +70 71 903 +47 63 99 +38 73 147 +89 45 569 +45 53 686 +29 62 53 +70 23 893 +65 14 172 +54 42 245 +33 11 762 +92 86 75 +80 92 248 +38 74 50 +46 70 264 +33 76 437 +36 86 981 +100 87 249 +25 4 761 +32 4 2 +30 88 862 +52 8 743 +57 43 175 +58 41 175 +22 48 464 +64 18 714 +100 51 141 +84 65 399 +46 97 565 +8 51 256 +3 50 968 +75 12 778 +58 70 715 +20 39 502 +34 8 949 +84 29 360 +86 42 752 +3 79 170 +52 56 852 +54 66 184 +55 40 168 +2 92 499 +44 78 212 +41 74 388 +83 29 690 +14 98 391 +40 97 728 +56 17 432 +40 36 22 +71 16 206 +97 85 753 +30 23 331 +47 38 107 +62 17 101 +92 1 725 +36 97 413 +62 2 679 +4 87 894 +44 98 521 +55 95 962 +55 3 416 +7 92 806 +88 36 290 +88 76 806 +50 64 362 +29 47 383 +38 27 825 +64 64 809 +69 64 489 +35 17 624 +100 9 376 +9 60 806 +9 46 745 +72 52 929 +14 15 471 +32 1 695 +85 98 843 +50 98 220 +29 9 795 +61 34 627 +46 33 994 +44 65 585 +55 78 736 +9 89 219 +49 69 606 +13 34 985 +91 75 301 +39 27 889 +49 53 56 +21 36 349 +94 66 841 +57 87 491 +31 21 127 +26 50 232 +15 47 365 +47 5 7 +4 97 961 +45 16 187 +83 31 121 +88 43 343 +92 38 365 +37 38 960 +60 37 978 +28 33 910 +40 84 0 +6 22 672 +72 1 611 +30 16 716 +85 46 997 +38 44 617 +60 5 90 +36 29 183 +98 51 450 +37 55 595 +78 46 646 +60 7 68 +20 90 928 +71 38 218 +74 11 143 +48 4 813 +36 8 714 +71 78 402 +60 44 942 +49 13 642 +86 57 586 +81 90 70 +88 98 623 +75 27 821 +56 11 8 +12 65 153 +6 74 619 +28 46 448 +36 18 931 +45 31 73 +21 59 321 +18 40 602 +38 49 380 +42 39 928 +32 36 703 +31 46 579 +76 77 407 +14 95 341 +89 46 853 +76 56 517 +52 76 597 +16 9 275 +98 37 115 +40 97 684 +40 31 608 +79 29 537 +34 30 571 +66 68 719 +51 83 198 +70 35 435 +66 4 824 +27 88 15 +27 12 417 +28 95 838 +75 34 40 +81 30 408 +85 32 653 +26 54 354 +2 60 264 +25 61 486 +81 83 707 +3 7 539 +42 24 847 +73 99 545 +71 11 221 +3 74 32 +100 65 981 +26 30 53 +82 54 66 +55 27 369 diff --git a/open_set/82_prim.pas b/open_set/82_prim.pas new file mode 100644 index 0000000..547b08b --- /dev/null +++ b/open_set/82_prim.pas @@ -0,0 +1,80 @@ +program main; +var +n, m: integer; +ret,i: integer; +u,v,c,fa: array [0..1004] of integer; + +function find(x: integer):integer; +var asdf: integer; +begin + if x = fa[x] then + find := x + else + begin + asdf := find(fa[x]); + fa[x] := asdf; + find := asdf; + end; +end; + +function same(x,y: integer):integer; +begin + x := find(x); + y := find(y); + if x = y then + same := 1 + else + same := 0; +end; + +function prim:integer; +var i,j,t,res: integer; +begin + for i := 0 to m - 1 do + begin + for j := i + 1 to m - 1 do + begin + if c[i] > c[j] then + begin + t := u[i]; + u[i] := u[j]; + u[j] := t; + t := v[i]; + v[i] := v[j]; + v[j] := t; + t := c[i]; + c[i] := c[j]; + c[j] := t; + end; + end; + end; + + for i := 1 to n do + fa[i] := i; + res := 0; + for i := 0 to m - 1 do + begin + if same(u[i], v[i]) = 0 then + begin + res := res + c[i]; + fa[find(u[i])] := v[i]; + end; + end; + + prim := res; +end; + +begin + ret := 0; + read(n); + read(m); + for i := 0 to m - 1 do + begin + read(u[i]); + read(v[i]); + read(c[i]); + end; + + ret := prim; + write(ret); +end. diff --git a/open_set/83_sort.in b/open_set/83_sort.in new file mode 100644 index 0000000..56f52fe --- /dev/null +++ b/open_set/83_sort.in @@ -0,0 +1,3 @@ +20 +1 2 3 4 5 6 7 8 9 0 +0 9 8 7 6 5 4 3 2 1 \ No newline at end of file diff --git a/open_set/83_sort.pas b/open_set/83_sort.pas new file mode 100644 index 0000000..68807dc --- /dev/null +++ b/open_set/83_sort.pas @@ -0,0 +1,92 @@ +program main; +var +n,ret,i,t: integer; +x,a,b,c: array[0..100004] of integer; +cnt: array [0..400019] of integer; + +procedure sortA; +var i, j, t:integer; +begin + for i := 0 to n - 1 do + begin + for j := i + 1 to n - 1 do + begin + if a[i] > a[j] then + begin + t := a[i]; + a[i] := a[j]; + a[j] := t; + end; + end; + end; +end; + +procedure sortB; +var mx,i,j,now: integer; +begin + mx := -100; + for i := 0 to n - 1 do + begin + cnt[b[i]] := cnt[b[i]] + 1; + if b[i] > mx then + mx := b[i]; + end; + now := 0; + for i := 0 to mx do + begin + for j := 0 to cnt[i] - 1 do + begin + b[now] := i; + now := now + 1; + end; + end; +end; + +procedure sortC; +var i,j,id: integer; +begin + for i := 0 to n - 1 do + begin + id := i; + for j := i + 1 to n - 1 do + begin + if c[j] < c[id] then + id := j; + end; + t := c[i]; + c[i] := c[id]; + c[id] := t; + end; +end; + +begin + ret := 0; + read(n); + + for i := 0 to n - 1 do + begin + read(a[i]); + b[i] := a[i]; + c[i] := b[i]; + end; + + sortA; + sortB; + sortC; + + for i := 0 to n - 1 do + begin + b[i] := b[i] - a[i]; + c[i] := c[i] - b[i] -a[i]; + end; + + for i := 0 to n - 1 do + begin + if b[i] <> 0 then + ret := 1; + if c[i] <> 0 then + ret := 2; + end; + ret := 0; + write(ret); +end. diff --git a/open_set/84_union_find.in b/open_set/84_union_find.in new file mode 100644 index 0000000..ee96652 --- /dev/null +++ b/open_set/84_union_find.in @@ -0,0 +1,28 @@ +20 27 +13 5 +3 18 +3 20 +11 1 +5 14 +7 9 +20 19 +13 16 +12 20 +7 5 +18 2 +11 14 +11 6 +1 13 +1 10 +3 17 +3 1 +8 12 +12 20 +9 2 +6 10 +19 15 +18 11 +19 12 +6 20 +18 2 +20 16 diff --git a/open_set/84_union_find.pas b/open_set/84_union_find.pas new file mode 100644 index 0000000..93744ca --- /dev/null +++ b/open_set/84_union_find.pas @@ -0,0 +1,60 @@ +program main; + +var + parent: array[0..1004] of integer; + n, m, i, p, q, clusters: integer; + +function getint: integer; +begin + read(getint); +end; + +function find(root: integer): integer; +begin + if parent[root] = root then + find := root + else + begin + parent[root] := find(parent[root]); + find := parent[root]; + end; +end; + +procedure merge(p, q: integer); +var + root_p, root_q: integer; +begin + root_p := find(p); + root_q := find(q); + if root_p <> root_q then + begin + parent[root_q] := root_p; + end; +end; + +begin + n := getint(); + m := getint(); + + for i := 0 to n - 1 do + begin + parent[i] := i; + end; + + for i := 0 to m - 1 do + begin + p := getint(); + q := getint(); + merge(p, q); + end; + + clusters := 0; + for i := 0 to n - 1 do + begin + if parent[i] = i then + clusters := clusters + 1; + end; + + write(clusters); + read(clusters); +end. diff --git a/open_set/85_matrix_multiply.in b/open_set/85_matrix_multiply.in new file mode 100644 index 0000000..b98a477 --- /dev/null +++ b/open_set/85_matrix_multiply.in @@ -0,0 +1,10 @@ +4 4 +1 2 3 4 +5 6 7 8 +9 10 11 12 +13 14 15 16 +4 3 +9 5 1 +10 6 2 +11 7 3 +12 8 4 \ No newline at end of file diff --git a/open_set/85_matrix_multiply.pas b/open_set/85_matrix_multiply.pas new file mode 100644 index 0000000..6a6c1ac --- /dev/null +++ b/open_set/85_matrix_multiply.pas @@ -0,0 +1,56 @@ +program main; + +var + a,b,res: array[1..100, 1..100] of integer; + n1, m1, n2, m2, i, j, k: integer; + +procedure matrix_multiply; +begin + for i := 1 to m1 do + begin + for j := 1 to n2 do + begin + for k := 1 to n1 do + begin + res[i][j] := res[i][j] + a[i][k] * b[k][j]; + end; + end; + end; +end; + +function getint: integer; +begin + read(getint); +end; + +begin + m1 := getint; + n1 := getint; + for i := 1 to m1 do + begin + for j := 1 to n1 do + begin + a[i][j] := getint; + end; + end; + + m2 := getint; + n2 := getint; + for i := 1 to m2 do + begin + for j := 1 to n2 do + begin + b[i][j] := getint; + end; + end; + + matrix_multiply; + + for i := 1 to m1 do + begin + for j := 1 to n2 do + begin + write(res[i][j]); + end; + end; +end. diff --git a/open_set/86_side_effect2.pas b/open_set/86_side_effect2.pas new file mode 100644 index 0000000..78245b8 --- /dev/null +++ b/open_set/86_side_effect2.pas @@ -0,0 +1,79 @@ +program main; +var +sum, i, ans: integer; +arr: array[0..19] of integer; + +function f(i, j: integer): integer; +begin + sum := sum + 1; + if (i >= j) or (i >= 20) then + f := 0 + else + begin + arr[i] := 1; + if i = 0 then + f := arr[0] + else + f := arr[i - 1]; + end; +end; + +function g(i,j: integer):integer; +begin + sum := sum + 2; + if (i >= j) or (i >= 20) then + g := 1 + else + begin + arr[i] := 0; + if i = 0 then + g := arr[0] + else + g := arr[i - 1]; + end; +end; + +function h(i: integer): integer; +begin + sum := sum + 3; + if (i < 0) or (i >= 20) then + h := 0 + else + h := arr[i]; +end; + +begin + for i := 0 to 19 do + arr[i] := 0; + for i := 0 to 19 do + begin + if (f(0, i) <> 0) and (f(1, i) <> 0) and (f(2, i) <> 0) and (f(3, i) <> 0) and (f(4, i) <> 0) and + (f(5, i) <> 0) and (f(6, i) <> 0) and (f(7, i) <> 0) and (f(8, i) <> 0) and (f(9, i) <> 0) and + (f(10, i) <> 0) and (f(11, i) <> 0) and (f(12, i) <> 0) and (f(13, i) <> 0) and (f(14, i) <> 0) and + (f(15, i) <> 0) and (f(16, i) <> 0) and (f(17, i) <> 0) and (f(18, i) <> 0) and (f(19, i) <> 0) then + ; + end; + + for i := 0 to 19 do + begin + if (g(0, i) <> 0) or (g(1, i) <> 0) or (g(2, i) <> 0) or (g(3, i) <> 0) or (g(4, i) <> 0) or + (g(5, i) <> 0) or (g(6, i) <> 0) or (g(7, i) <> 0) or (g(8, i) <> 0) or (g(9, i) <> 0) or + (g(10, i) <> 0) or (g(11, i) <> 0) or (g(12, i) <> 0) or (g(13, i) <> 0) or (g(14, i) <> 0) or + (g(15, i) <> 0) or (g(16, i) <> 0) or (g(17, i) <> 0) or (g(18, i) <> 0) or (g(19, i) <> 0) then + ; + end; + + ans := 0; + if (h(0) <> 0) and (h(1) <> 0) or (not (h(2) <> 0)) or (h(3) <> 0) then + ans := 1; + ans := 0; + if (not (h(4) <> 0)) or (h(5) <> 0) and (not (h(6) <> 0)) and (h(7) <> 0) or (not (h(8) <> 0)) then + ans := 1; + ans := 0; + if (h(9) <> 0) and (not (h(10) <> 0)) or (not (h(11) <> 0)) or (not (h(12) <> 0)) or (not (h(13) <> 0)) or (h(14) <> 0) and (h(15) <> 0) then + ans := 1; + ans := 0; + if (h(0) <> 0) and (h(2) <> 0) and (not (h(3) <> 0)) and (not (h(4) <> 0)) or (h(5) <> 0) or (h(6) <> 0) and (not (h(7) <> 0)) or (h(8) <> 0) then + ans := 1; + write(sum + ans); +end. diff --git a/open_set/87_long_line.pas b/open_set/87_long_line.pas new file mode 100644 index 0000000..c73acf8 --- /dev/null +++ b/open_set/87_long_line.pas @@ -0,0 +1 @@ +program main;var sum, i, ans: integer;arr: array[0..19] of integer;function f(i, j: integer): integer;begin sum := sum + 1;if (i >= j) or (i >= 20) then f := 0 else begin arr[i] := 1;if i = 0 then f := arr[0]else f := arr[i - 1];end;end;function g(i,j: integer):integer;begin sum := sum + 2;if (i >= j) or (i >= 20) then g := 1 else begin arr[i] := 0;if i = 0 then g := arr[0] else g := arr[i - 1];end;end;function h(i: integer): integer;begin sum := sum + 3;if (i < 0) or (i >= 20) then h := 0 else h := arr[i];end;begin for i := 0 to 19 do arr[i] := 0;for i := 0 to 19 do begin if (f(0, i) <> 0) and (f(1, i) <> 0) and (f(2, i) <> 0) and (f(3, i) <> 0) and (f(4, i) <> 0) and (f(5, i) <> 0) and (f(6, i) <> 0) and (f(7, i) <> 0) and (f(8, i) <> 0) and (f(9, i) <> 0) and (f(10, i) <> 0) and (f(11, i) <> 0) and (f(12, i) <> 0) and (f(13, i) <> 0) and (f(14, i) <> 0) and (f(15, i) <> 0) and (f(16, i) <> 0) and (f(17, i) <> 0) and (f(18, i) <> 0) and (f(19, i) <> 0) then;end;for i := 0 to 19 do begin if (g(0, i) <> 0) or (g(1, i) <> 0) or (g(2, i) <> 0) or (g(3, i) <> 0) or (g(4, i) <> 0) or (g(5, i) <> 0) or (g(6, i) <> 0) or (g(7, i) <> 0) or (g(8, i) <> 0) or (g(9, i) <> 0) or (g(10, i) <> 0) or (g(11, i) <> 0) or (g(12, i) <> 0) or (g(13, i) <> 0) or (g(14, i) <> 0) or (g(15, i) <> 0) or (g(16, i) <> 0) or (g(17, i) <> 0) or (g(18, i) <> 0) or (g(19, i) <> 0) then ;end;ans := 0;if (h(0) <> 0) and (h(1) <> 0) or (not (h(2) <> 0)) or (h(3) <> 0) then ans := 1;ans := 0;if (not (h(4) <> 0)) or (h(5) <> 0) and (not (h(6) <> 0)) and (h(7) <> 0) or (not (h(8) <> 0)) then ans := 1;ans := 0;if (h(9) <> 0) and (not (h(10) <> 0)) or (not (h(11) <> 0)) or (not (h(12) <> 0)) or (not (h(13) <> 0)) or (h(14) <> 0) and (h(15) <> 0) then ans := 1;ans := 0;if (h(0) <> 0) and (h(2) <> 0) and (not (h(3) <> 0)) and (not (h(4) <> 0)) or (h(5) <> 0) or (h(6) <> 0) and (not (h(7) <> 0)) or (h(8) <> 0) then ans := 1;write(sum + ans); end. \ No newline at end of file diff --git a/open_set/88_many_indirections.pas b/open_set/88_many_indirections.pas new file mode 100644 index 0000000..6be6af6 --- /dev/null +++ b/open_set/88_many_indirections.pas @@ -0,0 +1,20 @@ +program main; +const N=100;M=20; +var +arr: array[0..99, 0..19] of integer; +i,j,sum:integer; + +begin + for i := 0 to M -1 do + begin + for j := 0 to N - 1 do + begin + arr[i, j] := j; + end; + end; + sum := arr[0, arr[1, arr[2, arr[3, arr[4, arr[5, arr[6, arr[7, arr[8,arr[9,arr[10,arr[11,arr[12,arr[13,arr[14,arr[15,arr[16,arr[17,arr[18,arr[19,19]]]]]]]]]]]]]]]]]]]] + + arr[arr[arr[arr[arr[arr[arr[arr[arr[arr[arr[arr[arr + [arr[arr[arr[arr[arr[arr[arr[19,18], + 17],16],15],14],13],12],11],10],9],8],7],6],5],4],3],2],1],0],19]; + write(sum); +end. \ No newline at end of file diff --git a/open_set/89_many_params3.pas b/open_set/89_many_params3.pas new file mode 100644 index 0000000..8457ac4 --- /dev/null +++ b/open_set/89_many_params3.pas @@ -0,0 +1,72 @@ +program main; +var ret: integer; + +function func( aa,ab,ac,ad,ae,af,ag,ah,ai,aj,ak,al,am,an,ao,ap,aq,ar,as,at,au,av,aw,ax,ay,az, + ba,bb,bc,bd,be,bf,bg,bh,bi,bj,bk,bl,bm,bn,bo,bp,bq,br,bs,bt,bu,bv,bw,bx,by,bz, + ca,cb,cc,cd,ce,cf,cg,ch,ci,cj,ck,cl,cm,cn,co,cp,cq,cr,cs,ct,cu,cv,cw,cx,cy,cz, + da,db,dc,dd,de,df,dg,dh,di,dj,dk,dl,dm,dn,doo,dp,dq,dr,ds,dt,du,dv,dw,dx,dy,dz, + ea,eb,ec,ed,ee,ef,eg,eh,ei,ej,ek,el,em,en,eo,ep,eq,er,es,et,eu,ev,ew,ex,ey,ez, + fa,fb,fc,fd,fe,ff,fg,fh,fi,fj,fk,fl,fm,fn,fo,fp,fq,fr,fs,ft,fu,fv,fw,fx,fy,fz, + ga,gb,gc,gd,ge,gf,gg,gh,gi,gj,gk,gl,gm,gn,go,gp,gq,gr,gs,gt,gu,gv,gw,gx,gy,gz, + ha,hb,hc,hd,he,hf,hg,hh,hi,hj,hk,hl,hm,hn,ho,hp,hq,hr,hs,ht,hu,hv,hw,hx,hy,hz, + ia,ib,ic,id,ie,iff,ig,ih,ii,ij,ik,il,im,inn,io,ip,iq,ir,is,it,iu,iv,iw,ix,iy,iz, + ja,jb,jc,jd,je,jf,jg,jh,ji,jj,jk,jl,jm,jn,jo,jp,jq,jr,js,jt,ju,jv,jw,jx,jy,jz, + ka,kb,kc,kd,ke,kf,kg,kh,ki,kj,kk,kl,km,kn,ko,kp,kq,kr,ks,kt,ku,kv,kw,kx,ky,kz, + la,lb,lc,ld,le,lf,lg,lh,li,lj,lk,ll,lm,ln,lo,lp,lq,lr,ls,lt,lu,lv,lw,lx,ly,lz, + ma,mb,mc,md,me,mf,mg,mh,mi,mj,mk,ml,mm,mn,mo,mp,mq,mr,ms,mt,mu,mv,mw,mx,my,mz, + na,nb,nc,nd,ne,nf,ng,nh,ni,nj,nk,nl,nm,nn,no,np,nq,nr,ns,nt,nu,nv,nw,nx,ny,nz, + oa,ob,oc,od,oe,off,og,oh,oi,oj,ok,ol,om,on,oo,op,oq,orr,os,ot,ou,ov,ow,ox,oy,oz, + pa,pb,pc,pd,pe,pf,pg,ph,pi,pj,pk,pl,pm,pn,po,pp,pq,pr,ps,pt,pu,pv,pw,px,py,pz, + qa,qb,qc,qd,qe,qf,qg,qh,qi,qj,qk,ql,qm,qn,qo,qp,qq,qr,qs,qt,qu,qv,qw,qx,qy,qz, + ra,rb,rc,rd,re,rf,rg,rh,ri,rj,rk,rl,rm,rn,ro,rp,rq,rr,rs,rt,ru,rv,rw,rx,ry,rz, + sa,sb,sc,sd,se,sf,sg,sh,si,sj,sk,sl,sm,sn,so,sp,sq,sr,ss,st,su,sv,sw,sx,sy,sz, + ta,tb,tc,td,te,tf,tg,th,ti,tj,tk,tl,tm,tn,too,tp,tq,tr,ts,tt,tu,tv,tw,tx,ty,tz, + ua,ub,uc,ud,ue,uf,ug,uh,ui,uj,uk,ul,um,un,uo,up,uq,ur,us,ut,uu,uv,uw,ux,uy,uz, + va,vb,vc,vd,ve,vf,vg,vh,vi,vj,vk,vl,vm,vn,vo,vp,vq,vr,vs,vt,vu,vv,vw,vx,vy,vz, + wa,wb,wc,wd,we,wf,wg,wh,wi,wj,wk,wl,wm,wn,wo,wp,wq,wr,ws,wt,wu,wv,ww,wx,wy,wz, + xa,xb,xc,xd,xe,xf,xg,xh,xi,xj,xk,xl,xm,xn,xo,xp,xq,xr,xs,xt,xu,xv,xw,xx,xy,xz, + ya,yb,yc,yd,ye,yf,yg,yh,yi,yj,yk,yl,ym,yn,yo,yp,yq,yr,ys,yt,yu,yv,yw,yx,yy,yz, + za,zb,zc,zd,ze,zf,zg,zh,zi,zj,zk,zl,zm,zn,zo,zp,zq,zr,zs,zt,zu,zv,zw,zx,zy,zz: integer): integer; +begin + func := zi * xy * ve * zl * dk + ui + sd * bx * qr * kk * qk * jt * xj + wl * wg + kb + ii * vj * oa + pb * ku + ee * fv + ha + bm * jv * ka * mr + gv + qh + ci + az * lj * ie + pz * zg + js * wj * il * fx * vs + ed + te + ke + sq * hq * da + vb * gp + ab * kx * lc + pn * ae + cs * on + xe + zi + mf + sc * ak * ko + hx * ax + gc * cm + br * fl + ul + el + nt + tt * eh + gq + up * uj * kz + yj + ah * dl * xz * il * km * qp * yx + lc + re * qb + nl + on + gq + zs + ca * lh + ra + doo * op + cl * et * ad + + kb + tc + bb * oo + mg + ws * xj + ri * ty * mu + cy + dp * wm * wt + dw + pv + it + iy + it + za * hw + kx * pc * zs * ht * sv * jy + gk + cq * ym * vz * de * gg + fc * dk * yb * wm + zu + th * bn * iy * doo + al + vj * ex * di * jb * ss * bd * kn + yz + kw + tv * ug + iff * wx * fn * ul * tt * fp * hn * dv * zv * al * wr + fa * vv + ls + ia * ip * uv + li + zs + em + pa * zf + zb + bt + ad + jp + + ut + tm + et + ct + hc + en * hd * hf * cr * lm + pp * wj * nd * ka * ta + ru * jn + en + gc * jb + + kg * bf + sl + pr + uc + yv + vd * td * xg + cp * rj + qu + vw * ao * oz + zf + qj + kl * st * on * qq + mv * eu * ay * ih * ta * tm + vh + rz + yn * bp + pr + xt * lw + uo * zl * rv + fz * rz * fz + + mf * sj + xz * yt + qj + ki * gf + ne + gd + vz + oh + hh + ff + ec * xk + hb + pe + mz * yx * aw + + ij + dn + zj * nm + jj * kz * ic * sg + ue * yo + le + fg * kt * br * yx + so * qy + bd + da + iq + + go + uu + jj * le + xa + vs * qs + mq + vr + ua + hx * oz * sl * cj * hg + rd * bz + vk * ic + ib + + fj * au * dm + ve * ks + pl * oi * kd * iu + be * rr + va * hc * tl + wm + rq + ob + pg * hq + pe * ww * ei * rn + yk + oc * sh * ig * uu + cg * vu * yn + xj * wh + xf + wo + nr + vf * sa * yg + uj + + sb + dt + pn + ui + nc * bv + qa * ze * kn + zt * da + kw * xp + hy * hs + pb + ox * uz * pe + be * im + sg + tm * im + gh * ju * zx + fc + pn * ei * we + ae * re + wp * aj + pc * km * pm + hc * bt * ap * ik * am + yu + my + wh * ah * tt * fo + rx * te * al + tq + fj + df * ts + jl + lx + ov + inn; +end; + +begin + ret := 0; + ret := func( + 0, 1, 1, 8, 9, 5, 2, 0, 6, 2, 4, 7, 1, 6, 9, 3, 3, 5, 0, 8, 9, 3, 4, 5, 9, 0, + 8, 9, 5, 5, 4, 1, 4, 3, 5, 9, 7, 6, 1, 7, 5, 4, 0, 7, 5, 5, 6, 4, 9, 6, 6, 6, + 8, 0, 4, 2, 3, 3, 0, 5, 4, 3, 9, 5, 9, 3, 3, 6, 4, 3, 3, 0, 5, 0, 2, 5, 6, 6, + 9, 4, 0, 3, 7, 2, 1, 1, 9, 8, 4, 8, 5, 2, 5, 4, 5, 0, 3, 5, 0, 7, 0, 7, 5, 6, + 7, 7, 8, 2, 6, 8, 9, 4, 6, 7, 2, 9, 8, 8, 0, 0, 3, 4, 8, 9, 0, 5, 9, 8, 5, 1, + 2, 7, 3, 2, 5, 4, 9, 9, 6, 9, 2, 5, 5, 7, 8, 3, 8, 9, 4, 9, 0, 5, 9, 8, 4, 2, + 5, 0, 7, 8, 8, 4, 6, 7, 9, 8, 2, 4, 4, 2, 9, 9, 8, 1, 2, 3, 7, 2, 2, 1, 7, 1, + 2, 4, 0, 6, 6, 0, 9, 9, 0, 7, 8, 9, 8, 5, 1, 8, 9, 2, 4, 7, 3, 4, 7, 9, 9, 4, + 7, 1, 9, 0, 6, 0, 6, 9, 8, 4, 3, 6, 2, 9, 7, 5, 6, 9, 8, 6, 5, 8, 4, 0, 5, 2, + 3, 2, 4, 0, 0, 9, 5, 8, 9, 2, 5, 2, 5, 0, 9, 4, 2, 0, 0, 1, 5, 0, 4, 9, 4, 9, + 4, 6, 0, 0, 4, 2, 6, 9, 3, 7, 8, 5, 5, 7, 1, 0, 5, 3, 6, 0, 3, 3, 6, 2, 9, 9, + 1, 9, 6, 2, 4, 1, 5, 1, 5, 0, 8, 5, 7, 9, 4, 6, 1, 3, 9, 4, 2, 3, 0, 8, 6, 0, + 9, 7, 3, 1, 3, 7, 0, 9, 2, 3, 1, 2, 9, 3, 8, 5, 7, 3, 9, 6, 7, 1, 9, 6, 3, 8, + 1, 8, 8, 2, 8, 7, 5, 4, 2, 0, 4, 0, 7, 7, 8, 9, 6, 6, 7, 7, 1, 6, 0, 5, 3, 4, + 2, 6, 3, 6, 3, 4, 1, 3, 6, 9, 4, 3, 0, 9, 0, 2, 2, 0, 8, 8, 4, 5, 8, 2, 3, 3, + 7, 2, 5, 9, 6, 7, 0, 1, 8, 5, 7, 8, 3, 0, 2, 9, 1, 5, 4, 9, 4, 5, 3, 7, 4, 0, + 2, 7, 1, 3, 2, 7, 1, 7, 0, 0, 6, 7, 8, 9, 0, 2, 5, 4, 6, 2, 9, 2, 1, 0, 2, 2, + 7, 3, 8, 9, 6, 3, 6, 9, 0, 8, 1, 2, 2, 9, 5, 8, 2, 5, 0, 4, 7, 0, 8, 2, 9, 6, + 7, 7, 5, 2, 6, 6, 8, 8, 9, 7, 7, 4, 9, 0, 8, 7, 6, 8, 3, 1, 6, 7, 4, 6, 5, 6, + 2, 8, 8, 5, 9, 0, 3, 1, 9, 1, 4, 9, 6, 4, 7, 6, 6, 8, 9, 6, 6, 1, 2, 5, 2, 0, + 3, 8, 2, 9, 1, 3, 9, 6, 2, 3, 2, 9, 9, 3, 8, 8, 1, 9, 8, 5, 1, 1, 2, 7, 9, 3, + 7, 4, 3, 4, 0, 7, 4, 9, 1, 4, 6, 4, 3, 8, 3, 8, 7, 6, 3, 2, 1, 8, 5, 2, 3, 1, + 3, 7, 6, 2, 4, 0, 9, 9, 7, 8, 3, 7, 5, 8, 8, 5, 6, 7, 3, 2, 9, 5, 5, 1, 5, 7, + 9, 7, 9, 0, 5, 4, 3, 3, 0, 0, 0, 3, 5, 1, 6, 2, 0, 4, 7, 4, 9, 7, 3, 4, 0, 6, + 0, 3, 1, 3, 5, 7, 3, 8, 3, 1, 9, 6, 8, 6, 7, 7, 3, 2, 9, 8, 1, 9, 5, 8, 4, 7, + 8, 9, 9, 0, 9, 2, 9, 0, 0, 7, 4, 3, 9, 2, 2, 7, 8, 7, 1, 3, 5, 8, 4, 4, 0, 9); + write(ret); +end. diff --git a/open_set/90_multi_branch.pas b/open_set/90_multi_branch.pas new file mode 100644 index 0000000..b770250 --- /dev/null +++ b/open_set/90_multi_branch.pas @@ -0,0 +1,309 @@ +program main; +var a,res,n,i: integer; +begin + n := 2; + for i := 0 to n - 1 do + begin + res := 0; + a := 1; + if (a > 0) and (a < 100) then + if (a > 0) and (a < 99) then + if (a > 0) and (a < 98) then + if (a > 0) and (a < 97) then + if (a > 0) and (a < 96) then + if (a > 0) and (a < 95) then + if (a > 0) and (a < 94) then + if (a > 0) and (a < 93) then + if (a > 0) and (a < 92) then + if (a > 0) and (a < 91) then + if (a > 0) and (a < 90) then + if (a > 0) and (a < 89) then + if (a > 0) and (a < 88) then + if (a > 0) and (a < 87) then + if (a > 0) and (a < 86) then + if (a > 0) and (a < 85) then + if (a > 0) and (a < 84) then + if (a > 0) and (a < 83) then + if (a > 0) and (a < 82) then + if (a > 0) and (a < 81) then + if (a > 0) and (a < 80) then + if (a > 0) and (a < 79) then + if (a > 0) and (a < 78) then + if (a > 0) and (a < 77) then + if (a > 0) and (a < 76) then + if (a > 0) and (a < 75) then + if (a > 0) and (a < 74) then + if (a > 0) and (a < 73) then + if (a > 0) and (a < 72) then + if (a > 0) and (a < 71) then + if (a > 0) and (a < 70) then + if (a > 0) and (a < 69) then + if (a > 0) and (a < 68) then + if (a > 0) and (a < 67) then + if (a > 0) and (a < 66) then + if (a > 0) and (a < 65) then + if (a > 0) and (a < 64) then + if (a > 0) and (a < 63) then + if (a > 0) and (a < 62) then + if (a > 0) and (a < 61) then + if (a > 0) and (a < 60) then + if (a > 0) and (a < 59) then + if (a > 0) and (a < 58) then + if (a > 0) and (a < 57) then + if (a > 0) and (a < 56) then + if (a > 0) and (a < 55) then + if (a > 0) and (a < 54) then + if (a > 0) and (a < 53) then + if (a > 0) and (a < 52) then + if (a > 0) and (a < 51) then + if (a > 0) and (a < 50) then + if (a > 0) and (a < 49) then + if (a > 0) and (a < 48) then + if (a > 0) and (a < 47) then + if (a > 0) and (a < 46) then + if (a > 0) and (a < 45) then + if (a > 0) and (a < 44) then + if (a > 0) and (a < 43) then + if (a > 0) and (a < 42) then + if (a > 0) and (a < 41) then + if (a > 0) and (a < 40) then + if (a > 0) and (a < 39) then + if (a > 0) and (a < 38) then + if (a > 0) and (a < 37) then + if (a > 0) and (a < 36) then + if (a > 0) and (a < 35) then + if (a > 0) and (a < 34) then + if (a > 0) and (a < 33) then + if (a > 0) and (a < 32) then + if (a > 0) and (a < 31) then + if (a > 0) and (a < 30) then + if (a > 0) and (a < 29) then + if (a > 0) and (a < 28) then + if (a > 0) and (a < 27) then + if (a > 0) and (a < 26) then + if (a > 0) and (a < 25) then + if (a > 0) and (a < 24) then + if (a > 0) and (a < 23) then + if (a > 0) and (a < 22) then + if (a > 0) and (a < 21) then + if (a > 0) and (a < 20) then + if (a > 0) and (a < 19) then + if (a > 0) and (a < 18) then + if (a > 0) and (a < 17) then + if (a > 0) and (a < 16) then + if (a > 0) and (a < 15) then + if (a > 0) and (a < 14) then + if (a > 0) and (a < 13) then + if (a > 0) and (a < 12) then + if (a > 0) and (a < 11) then + if (a > 0) and (a < 10) then + if (a > 0) and (a < 9) then + if (a > 0) and (a < 8) then + if (a > 0) and (a < 7) then + if (a > 0) and (a < 6) then + if (a > 0) and (a < 5) then + if (a > 0) and (a < 4) then + if (a > 0) and (a < 3) then + if (a > 0) and (a < 2) then + res := res + 1 + else + res := res + 2 + else + res := res + 3 + else + res := res + 4 + else + res := res + 5 + else + res := res + 6 + else + res := res + 7 + else + res := res + 8 + else + res := res + 9 + else + res := res + 10 + else + res := res + 11 + else + res := res + 12 + else + res := res + 13 + else + res := res + 14 + else + res := res + 15 + else + res := res + 16 + else + res := res + 17 + else + res := res + 18 + else + res := res + 19 + else + res := res + 20 + else + res := res + 21 + else + res := res + 22 + else + res := res + 23 + else + res := res + 24 + else + res := res + 25 + else + res := res + 26 + else + res := res + 27 + else + res := res + 28 + else + res := res + 29 + else + res := res + 30 + else + res := res + 31 + else + res := res + 32 + else + res := res + 33 + else + res := res + 34 + else + res := res + 35 + else + res := res + 36 + else + res := res + 37 + else + res := res + 38 + else + res := res + 39 + else + res := res + 40 + else + res := res + 41 + else + res := res + 42 + else + res := res + 43 + else + res := res + 44 + else + res := res + 45 + else + res := res + 46 + else + res := res + 47 + else + res := res + 48 + else + res := res + 49 + else + res := res + 50 + else + res := res + 51 + else + res := res + 52 + else + res := res + 53 + else + res := res + 54 + else + res := res + 55 + else + res := res + 56 + else + res := res + 57 + else + res := res + 58 + else + res := res + 59 + else + res := res + 60 + else + res := res + 61 + else + res := res + 62 + else + res := res + 63 + else + res := res + 64 + else + res := res + 65 + else + res := res + 66 + else + res := res + 67 + else + res := res + 68 + else + res := res + 69 + else + res := res + 70 + else + res := res + 71 + else + res := res + 72 + else + res := res + 73 + else + res := res + 74 + else + res := res + 75 + else + res := res + 76 + else + res := res + 77 + else + res := res + 78 + else + res := res + 79 + else + res := res + 80 + else + res := res + 81 + else + res := res + 82 + else + res := res + 83 + else + res := res + 84 + else + res := res + 85 + else + res := res + 86 + else + res := res + 87 + else + res := res + 88 + else + res := res + 89 + else + res := res + 90 + else + res := res + 91 + else + res := res + 92 + else + res := res + 93 + else + res := res + 94 + else + res := res + 95 + else + res := res + 96 + else + res := res + 97 + else + res := res + 98 + else + res := res + 99 + else + res := res + 100; + write(res); + end; +end. diff --git a/open_set/91_multi_loop.pas b/open_set/91_multi_loop.pas new file mode 100644 index 0000000..a1814f5 --- /dev/null +++ b/open_set/91_multi_loop.pas @@ -0,0 +1,54 @@ +program NestedLoops; +var + a, i, j, k, ii, jj, kk, iii, jjj, kkk, iiii, jjjj, kkkk, iiiii, jjjjj, kkkkk: integer; +begin + a := 0; + for i := 0 to 2 do + begin + for j := 0 to 3 do + begin + for k := 0 to 4 do + begin + for ii := 0 to 2 do + begin + for jj := 0 to 4 do + begin + for kk := 0 to 3 do + begin + for iii := 0 to 5 do + begin + for jjj := 0 to 4 do + begin + for kkk := 0 to 4 do + begin + for iiii := 0 to 2 do + begin + for jjjj := 0 to 5 do + begin + for kkkk := 0 to 6 do + begin + for iiiii := 0 to 4 do + begin + for jjjjj := 0 to 2 do + begin + for kkkkk := 0 to 5 do + begin + a := (a + 3) mod 999; + end; + end; + end; + end; + end; + end; + end; + end; + end; + end; + end; + end; + end; + end; + end; + + write(a); +end. diff --git a/open_set/92_math.in b/open_set/92_math.in new file mode 100644 index 0000000..b19768e --- /dev/null +++ b/open_set/92_math.in @@ -0,0 +1 @@ +2.0 3.0 5.5 6.6 \ No newline at end of file diff --git a/open_set/92_math.pas b/open_set/92_math.pas new file mode 100644 index 0000000..6583e8f --- /dev/null +++ b/open_set/92_math.pas @@ -0,0 +1,163 @@ +program main; +const e = 2.1718281828459045; +split = '--'; +var +x,y:real; +num,i:integer; + +function my_fabs(x: real):real; +begin + if x > 0 then + my_fabs := x + else + my_fabs := -x; +end; + +function my_pow(a:real; n: integer):real; +var i:integer; res: real; +begin + if n < 0 then + my_pow := 1 / (my_pow(a, -n)) + else + begin + res := 1.0; + for i := 0 to n - 1 do + res := res * a; + my_pow := res; + end; +end; + +function my_sqrt(x:real):real; +var t:real; c:integer; +begin + if x > 100 then + my_sqrt := 10.0 * my_sqrt(x / 100) + else + begin + t := x / 8 + 0.5 + 2 * x / (4 + x); + for c := 0 to 9 do + t := (t + x / t) / 2; + my_sqrt := t; + end +end; + +function F1(x:real):real; +begin + F1 := 1 / x; +end; + +function F2(x:real):real; +begin + F2 := 1 / my_sqrt(1 - x * x); +end; + +function simpson(a,b: real; flag: integer): real; +var c:real; +begin + c := a + (b - a) / 2; + simpson := 0; + if flag = 1 then + simpson := (F1(a) + 4 * F1(c) + F1(b)) * (b - a) / 6 + else + simpson := (F2(a) + 4 * F2(c) + F2(b)) * (b - a) / 6; +end; + +function asr5(a,b,eps,AA: real; flag:integer):real; +var c,L,R:real; +begin + c := a + (b - a) / 2; + L := simpson(a, c, flag); + R := simpson(c, b, flag); + if my_fabs(L + R - AA) <= (15 * eps) then + asr5 := L + R + (L + R - AA) / 15.0 + else + asr5 := asr5(a, c, eps/2, L, flag) + asr5(c, b, eps/2, R, flag); +end; + +function asr4(a,b,eps:real; flag: integer):real; +begin + asr4 := asr5(a, b, eps, simpson(a, b, flag), flag); +end; + +function eee(x:real):real; +var ee: real; +begin + if x > 0.001 then + begin + ee := eee(x / 2); + eee := ee * ee; + end + else + eee := 1 + x + x * x / 2 + my_pow(x, 3) / 6 + my_pow(x, 4) / 24 + my_pow(x, 5) / 120; +end; + +function my_exp(x:real):real; +var e1,e2: real; n: integer; +begin + if x < 0 then + my_exp := 1 / my_exp(-x) + else + begin + //pascal no cut the integer part and float part + n := 1; + x := x - 1.0; + e1 := my_pow(e, n); + e2 := eee(x); + my_exp := e1 * e2; + end; +end; + +function my_ln(x:real):real; +begin + my_ln := asr4(1, x, 0.00000001, 1); +end; + +function my_log(a,N: real):real; +begin + my_log := my_ln(N) / my_ln(a); +end; + +function my_powf(a,x:real):real; +begin + my_powf := my_exp(x * my_ln(a)); +end; + +procedure putfloat(f:real); +begin + write(f); +end; + + +function getfloat():real; +begin + read(getfloat); +end; + +begin + num := 2; + for i := 0 to num - 1 do + begin + x := getfloat; + y := getfloat; + putfloat(my_fabs(x)); + putfloat(my_pow(x, 2)); + putfloat(my_sqrt(x)); + putfloat(my_exp(x)); + + if x > 0.0 then + putfloat(my_ln(x)) + else + write(split); + + if (x > 0.0) and (y > 0.0) then + putfloat(my_log(x, y)) + else + write(split); + + if x > 0.0 then + putfloat(my_powf(x, y)) + else + write(split); + end; + read(num); +end. diff --git a/open_set/93_dct.in b/open_set/93_dct.in new file mode 100644 index 0000000..b25af96 --- /dev/null +++ b/open_set/93_dct.in @@ -0,0 +1,4 @@ +3 3 +1.01 2.02 3.03 +2.02 3.03 1.01 +3.03 2.02 1.01 \ No newline at end of file diff --git a/open_set/93_dct.pas b/open_set/93_dct.pas new file mode 100644 index 0000000..d5eeb80 --- /dev/null +++ b/open_set/93_dct.pas @@ -0,0 +1,127 @@ +program main; +const +PI = 3.14159265359; +TWO_PI = 6.28318530718; +EPSILON = 0.000001; +var +test_block, test_dct, test_idct: array [0..7, 0..7] of real; +dim_x, dim_y, i, j: integer; + +function my_fabs(x: real): real; +begin + if x > 0.0 then + my_fabs := x + else + my_fabs := -x; +end; + +function p(x: real): real; +begin + p := 3 * x - 4 * x * x * x; +end; + +function my_sin_impl(x: real): real; +begin + if my_fabs(x) <= EPSILON then + my_sin_impl := x + else + my_sin_impl := p(my_sin_impl(x / 3.0)); +end; + +function my_sin(x: real): real; +var xx: integer; +begin + if (x > TWO_PI) or (x < -TWO_PI) then + begin + xx := 1; + x := x - 1.0; + end; + if x > PI then + x := x - TWO_PI; + if x < -PI then + x := x + TWO_PI; + my_sin := my_sin_impl(x); +end; + +function my_cos(x: real): real; +begin + my_cos := my_sin(x * PI / 2); +end; + +procedure write_mat(n, m: integer); +var i,j: integer; +begin + for i := 0 to n - 1 do + begin + write(test_dct[i, 0]); + for j := 1 to m - 1 do + write(test_dct[i, j]); + end; +end; + +procedure write_mat2(n, m: integer); +var i,j: integer; +begin + for i := 0 to n - 1 do + begin + write(test_idct[i, 0]); + for j := 1 to m - 1 do + write(test_idct[i, j]); + end; +end; + +procedure dct(n, m: integer); +var u, v, i, j: integer; +begin + for u := 0 to n - 1 do + begin + for v := 0 to m - 1 do + begin + test_dct[u, v] := 0; + for i := 0 to n - 1 do + begin + for j := 0 to m - 1 do + begin + test_dct[u, v] := test_dct[u, v] + test_block[i, j] * my_cos(PI / n * (i + 1.0 / 2.0) * u) * my_cos(PI / m * (i + 1.0 / 2.0) * v); + end; + end; + end; + end; +end; + +procedure idct(n, m: integer); +var u, v, i, j: integer; +begin + for u := 0 to n - 1 do + begin + for v := 0 to m - 1 do + begin + test_idct[u, v] := 1 / 4.0 * test_dct[0, 0]; + for i := 1 to n - 1 do + test_idct[u, v] := test_idct[u, v] + 1 / 2.0 * test_dct[i, 0]; + for j := 1 to m - 1 do + test_idct[u, v] := test_idct[u, v] + 1 / 2.0 * test_dct[0, j]; + for i := 1 to n - 1 do + for j := 1 to m - 1 do + test_idct[u, v] := test_idct[u, v] + test_dct[i, j] * my_cos(PI / n * (u + 1.0 / 2.0) * i) * my_cos(PI / m * (v + 1.0 / 2.0) * j); + test_idct[u, v] := test_idct[u, v] * 2.0 / n * 2.0 / m; + end; + end; +end; + +begin + dim_x := 0; + dim_y := 0; + read(dim_x); + read(dim_y); + + for i := 0 to dim_x - 1 do + for j := 0 to dim_y - 1 do + read(test_block[i, j]); + + dct(dim_x, dim_y); + write_mat(dim_x, dim_y); + + idct(dim_x, dim_y); + write_mat2(dim_x, dim_y); +end. diff --git a/open_set/94_fp_params.pas b/open_set/94_fp_params.pas new file mode 100644 index 0000000..9ccc84f --- /dev/null +++ b/open_set/94_fp_params.pas @@ -0,0 +1,126 @@ +program main; +var +k: integer; +i,j: integer; +ret0, ret1: real; +arr: array[0..39, 0..2] of real; +arr2: array[0..23, 0..2] of integer; + +function params_f40(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, + x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, + x25, x26, x27, x28, x29, x30, x31, x32, x33, x34, x35, + x36, x37, x38, x39: real): real; +var +i: integer; +arr: array[0..9] of real; +begin + if x39 <> 0 then + begin + arr[0] := x0+x1+x2+x3; + arr[1] := x4+x5+x6+X7; + arr[2] := x8+x9+x10+x11; + arr[3] := x12+x13+x14+x15; + arr[4] := x16+x17+x18+x19; + arr[5] := x20+x21+x22+x23; + arr[6] := x24+x25+x26+x27; + arr[7] := x28+x29+x30+x31; + arr[8] := x32+x33+x34+x35; + arr[9] := x36+x37+x38+x39; + for i := 0 to 9 do + write(arr[i]); + params_f40 := arr[k]; + end + else + begin + params_f40 := params_f40(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, + x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, + x25, x26, x27, x28, x29, x30, x31, x32, x33, x34, x35, + x36, x37, x38, x39, x0 + x1 + x2); + end; +end; + +function params_f40_i24(i23, i2, i6: integer; x4: real; i1, i4, i5: integer; + x8, x15, x7: real; i22: integer; x3: real; + x28: real; i0: integer; x37: real; i19: integer; x30: real; + x12, x1, x11, x38, x6: real; i7: integer; x32: real; i10, i13: integer; + x20, x33, x23, x9, x25: real; i8: integer; x39: real; i17: integer; + x21, x16, x5, x34: real; i18, i9: integer; x14, x10, x0: real; + i12: integer; x31: real; i11, i16: integer; x27, x24, x13, x29: real; + i3, i21, i20: integer; x18, x19, x22, x26, x36, x17: real; + i15: integer; x2: real; i14: integer; x35: real): real; +var +i : integer; +arr : array[0..9] of real; +arr2: array[0..7] of real; +begin + if i23 <> 0 then + begin + arr[0] := x0+x1+x2+x3; + arr[1] := x4+x5+x6+X7; + arr[2] := x8+x9+x10+x11; + arr[3] := x12+x13+x14+x15; + arr[4] := x16+x17+x18+x19; + arr[5] := x20+x21+x22+x23; + arr[6] := x24+x25+x26+x27; + arr[7] := x28+x29+x30+x31; + arr[8] := x32+x33+x34+x35; + arr[9] := x36+x37+x38+x39; + arr2[0] := (i0 + i1 + i2) * 1.0; + arr2[1] := (i3 + i4 + i5) * 1.0; + arr2[2] := (i6 + i7 + i8) * 1.0; + arr2[3] := (i9 + i10 + i11) * 1.0; + arr2[4] := (i12 + i13 + i14) * 1.0; + arr2[5] := (i15 + i16 + i17) * 1.0; + arr2[6] := (i18 + i19 + i20) * 1.0; + arr2[7] := (i21 + i22 + i23) * 1.0; + for i := 0 to 9 do + write(arr[i]); + for i := 0 to 7 do + write(arr2[i]); + for i := 0 to 7 do + arr2[i] := arr2[i] - arr[i]; + params_f40_i24 := arr2[k]; + end + else + params_f40_i24 := params_f40_i24(i1, i2, i6, x4, i1, i4, i5, x8, x15, x7, i22, x3, x28, + i0, x37, i19, x30, x12, x1, x11, x38, x6, i7, x32, + i10, i13, x20, x33, x23, x9, x25, i8, x39, i17, x21, + x16, x5, x34, i18, i9, x14, x10, x0, i12, x31, i11, + i16, x27, x24, x13, x29, i3, i21, i20, x18, x19, x22, + x26, x36, x17, i15, x2, i14, x35); +end; + +begin + k := 0; + for i := 0 to 23 do + for j := 0 to 2 do + arr2[i ,j] := i * 2 - j * 3; + for i := 0 to 39 do + for j := 0 to 2 do + arr[i, j] := i * 2.2 - j * 3.3; + + ret0 := params_f40( + arr[0][k], arr[1][k], arr[2][k], arr[3][k], arr[4][k], arr[5][k], + arr[6][k], arr[7][k], arr[8][k], arr[9][k], arr[10][k], arr[11][k], + arr[12][k], arr[13][k], arr[14][k], arr[15][k], arr[16][k], arr[17][k], + arr[18][k], arr[19][k], arr[20][k], arr[21][k], arr[22][k], arr[23][k], + arr[24][k], arr[25][k], arr[26][k], arr[27][k], arr[28][k], arr[29][k], + arr[30][k], arr[31][k], arr[32][k], arr[33][k], arr[34][k], arr[35][k], + arr[36][k], arr[37][k], arr[38][k], arr[39][k]); + + ret1 := params_f40_i24( + arr2[23][k], arr2[2][k], arr2[6][k], arr[4][k], arr2[1][k], arr2[4][k], + arr2[5][k], arr[8][k], arr[15][k], arr[7][k], arr2[22][k], arr[3][k], + arr[28][k], arr2[0][k], arr[37][k], arr2[19][k], arr[30][k], arr[12][k], + arr[1][k], arr[11][k], arr[38][k], arr[6][k], arr2[7][k], arr[32][k], + arr2[10][k], arr2[13][k], arr[20][k], arr[33][k], arr[23][k], arr[9][k], + arr[25][k], arr2[8][k], arr[39][k], arr2[17][k], arr[21][k], arr[16][k], + arr[5][k], arr[34][k], arr2[18][k], arr2[9][k], arr[14][k], arr[10][k], + arr[0][k], arr2[12][k], arr[31][k], arr2[11][k], arr2[16][k], arr[27][k], + arr[24][k], arr[13][k], arr[29][k], arr2[3][k], arr2[21][k], arr2[20][k], + arr[18][k], arr[19][k], arr[22][k], arr[26][k], arr[36][k], arr[17][k], + arr2[15][k], arr[2][k], arr2[14][k], arr[35][k]); + + write(ret0); + write(ret1); +end.