Var a:array of array of integer; jmin:array of integer; n,m,i,j,k,min:integer; begin Randomize; write('n = '); readln(n); write('m = '); readln(m); writeln('Исходный массив:'); SetLength(a,n); for i:=0 to n-1 do SetLength(a[i],m); SetLength(jmin,m); for i:=0 to n-1 do begin for j:=0 to m-1 do begin a[i,j]:=random(11); write(a[i,j]:4); end; writeln; end; min:=a[0,0]; jmin[0]:=1; for i:=0 to n-1 do for j:=0 to m-1 do if a[i,j]<min then begin min:=a[i,j]; for k:=0 to m-1 do jmin[k]:=0; jmin[j]:=1; end else if a[i,j]=min then jmin[j]:=1; writeln('min = ',min); for k:=0 to m-1 do write(jmin[k],' '); writeln; for k:=m-1 downto 0 do if jmin[k]=1 then begin for i:=0 to n-1 do SetLength(a[i],Length(a[i])+1); for i:=0 to n-1 do for j:=Length(a[i])-1 downto k+2 do a[i,j]:=a[i,j-1]; for i:=0 to n-1 do a[i,k+1]:=0; end; for i:=0 to n-1 do begin for j:=0 to Length(a[i])-1 do write(a[i,j]:4); writeln; end; end.
Answers & Comments
Verified answer
Vara:array of array of integer;
jmin:array of integer;
n,m,i,j,k,min:integer;
begin
Randomize;
write('n = ');
readln(n);
write('m = ');
readln(m);
writeln('Исходный массив:');
SetLength(a,n);
for i:=0 to n-1 do SetLength(a[i],m);
SetLength(jmin,m);
for i:=0 to n-1 do
begin
for j:=0 to m-1 do
begin
a[i,j]:=random(11);
write(a[i,j]:4);
end;
writeln;
end;
min:=a[0,0]; jmin[0]:=1;
for i:=0 to n-1 do
for j:=0 to m-1 do
if a[i,j]<min then
begin
min:=a[i,j];
for k:=0 to m-1 do jmin[k]:=0;
jmin[j]:=1;
end
else if a[i,j]=min then jmin[j]:=1;
writeln('min = ',min);
for k:=0 to m-1 do write(jmin[k],' ');
writeln;
for k:=m-1 downto 0 do
if jmin[k]=1 then
begin
for i:=0 to n-1 do SetLength(a[i],Length(a[i])+1);
for i:=0 to n-1 do
for j:=Length(a[i])-1 downto k+2 do a[i,j]:=a[i,j-1];
for i:=0 to n-1 do a[i,k+1]:=0;
end;
for i:=0 to n-1 do
begin
for j:=0 to Length(a[i])-1 do write(a[i,j]:4);
writeln;
end;
end.
Пример:
n = 4
m = 5
Исходный массив:
7 3 7 6 0
5 0 8 0 9
2 1 9 6 10
2 0 3 6 0
min = 0
0 1 0 1 1
7 3 0 7 6 0 0 0
5 0 0 8 0 0 9 0
2 1 0 9 6 0 10 0
2 0 0 3 6 0 0 0