Program Rome type point record integer end var arr array of point addi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Program Rome;
type point = record
x, y: integer;
end;
var arr: array of point;
additionally: array of point;
middle: point;
n: integer;
function calculateLength(point1, point2, middle: point): integer;
begin
calculateLength := abs(point1.x - middle.x) + abs(point1.y - point2.y) + abs(point2.x - middle.x);
end;
Begin
n := 5;
setLength(arr, n);
arr[0].x := 1; arr[0].y := 2;
arr[1].x := 2; arr[1].y := 1;
arr[2].x := 3; arr[2].y := 5;
arr[3].x := 4; arr[3].y := 4;
arr[4].x := 6; arr[4].y := 2;
//findMiddle return arr2
for var kek := 0 to n - 1 do begin
middle := arr[kek];
for var i := 0 to n - 1 do begin
for var j := 0 to n - 1 do begin
if(i <> j) then begin
//writeln(i + 1, ' - ', j + 1, ' = ', calculateLength(arr[i], arr[j], middle));
end;
end;
end;
var max_y, min_y: integer;
max_y := 0;
min_y := 9999;
for var i := 0 to n - 1 do begin
if (max_y < arr[i].y) then begin
max_y := arr[i].y;
end;
if (min_y > arr[i].y) then begin
min_y := arr[i].y;
end;
end;
var middle_length: integer;
middle_length := abs(max_y - min_y);
var length: integer;
length := middle_length;
for var i := 0 to (n - 1) do begin
length += abs(arr[i].x - middle.x);
end;
writeln(length);
end;
var temp: integer;
end.