Const n=8; var a:array[1..n,1..n] of integer; i,j,k,s,s1,si,dmin,smin:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=random(50); write(a[i,j]:4); end; writeln; end; write('k = '); readln(k); s:=0; for j:=1 to n do s:=s+a[k,j]; writeln('s = ',s); dmin:=999999; smin:=999999; for i:=1 to n do if i<>k then begin s1:=0; for j:=1 to n do s1:=s1+a[i,j]; writeln('s',i,' = ',s1); if abs(s1-s)<dmin then begin dmin:=abs(s1-s); smin:=s1; si:=i; end; end; writeln('Номер строки = ',si,', smin = ',smin); end.
var
a:array[1..n,1..n] of integer;
i,j,k,s,s1,si,dmin,smin:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=random(50);
write(a[i,j]:4);
end;
writeln;
end;
write('k = '); readln(k);
s:=0;
for j:=1 to n do s:=s+a[k,j];
writeln('s = ',s);
dmin:=999999; smin:=999999;
for i:=1 to n do
if i<>k then
begin
s1:=0;
for j:=1 to n do s1:=s1+a[i,j];
writeln('s',i,' = ',s1);
if abs(s1-s)<dmin then begin dmin:=abs(s1-s); smin:=s1; si:=i; end;
end;
writeln('Номер строки = ',si,', smin = ',smin);
end.
Пример:
Исходный массив:
9 0 22 40 20 35 2 25
23 30 22 35 41 0 9 40
1 15 6 18 43 47 34 33
26 5 2 45 13 46 40 2
26 39 7 31 3 43 20 8
25 15 24 6 10 16 3 25
47 0 27 35 14 15 36 11
16 38 14 14 33 7 11 26
k = 5
s = 177
s1 = 153
s2 = 200
s3 = 197
s4 = 179
s6 = 124
s7 = 185
s8 = 159
Номер строки = 4, smin = 179
begin
SetWindowWidth(800);
SetWindowHeight(900);
SetPenWidth(1);
PutPixel(400, 400, clred);
Line(0, 150, 100, 150);
Line(0, 150, 100, 200);
Line(100, 150, 150, 100);
Line(100, 50, 200, 150);
Line(100, 50, 200, 0);
Line(200, 0, 250, 50);
Line(250, 50, 300, 0);
Line(300, 0, 300, 100);
Line(300, 100, 350, 100);
Line(350, 100, 250, 150);
Line(250, 150, 300, 350);
Line(300, 350, 400, 400);
Line(50, 300, 100, 200);
Line(50, 300, 100, 250);
Line(100, 250, 150, 550);
Line(150, 550, 300, 650);
Line(400, 400, 500, 250);
Line(500, 250, 650, 250);
Line(650, 250, 750, 450);
Line(750, 450, 650, 400);
Line(650, 400, 550, 500);
Line(550, 500, 650, 450);
Line(750, 600, 650, 450);
Line(600, 550, 750, 600);
Line(700, 700, 600, 550);
Line(500, 600, 700, 700);
Line(400, 650, 500, 600);
Line(400, 800, 400, 650);
Line(450, 850, 400, 800);
Line(250, 850, 450, 850);
Line(350, 800, 250, 850);
Line(300, 650, 350, 800);
end.