Const n=7; var a:array[1..n,1..n] of integer; i,j,imax,jmax:integer; begin Randomize; imax:=1; jmax:=1; Writeln('Исходный массив'); for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=Random(90)+10; Write(a[i,j]:3); if a[i,j]>a[imax,jmax] then begin imax:=i; jmax:=j end; end; Writeln end; Writeln('Max[',imax,',',jmax,']=',a[imax,jmax]) end.
function minind(ar:ty;n:integer):integer; Var i,mini:integer; min:real; begin min:=11; for i:=1 to n do if ar[i]<min then begin min:=ar[i]; mini:=i; end; minind:=mini; end;
function sum1to2(ar:ty;n:integer):real; Var i,t1,t2:integer; r:real; begin for i:=1 to n do if ar[i]<0 then begin t1:=i; break; end; for i:=t1+1 to n do if ar[i]<0 then begin t2:=i; break; end; for i:=t1+1 to t2-1 do r:=r+ar[i]; sum1to2:=r; end;
procedure stransort(var ar:ty;n:integer); Var i,j,nd:integer; begin nd:=0; for i:=1 to n do if abs(ar[i])<=1 then begin inc(nd); swap(ar[i],ar[nd]); end; end;
Var ar:ty; i,n:integer; begin randomize; readln(n); writeln('Array:'); for i:=1 to n do begin ar[i]:=random(-3,3); write(ar[i]:4); end; writeln; writeln('Index of minimum:',minind(ar,n)); writeln('Sum=',sum1to2(ar,n)); stransort(ar,n); writeln('Final array:'); for i:=1 to n do write(ar[i]:4); end. Пример ввода: 5 Пример вывода: Array: 3 2 1 2 1 Index of minimum:3 Sum=0 Final array: 1 1 3 2 2
n=7;
var
a:array[1..n,1..n] of integer;
i,j,imax,jmax:integer;
begin
Randomize;
imax:=1; jmax:=1;
Writeln('Исходный массив');
for i:=1 to n do begin
for j:=1 to n do begin
a[i,j]:=Random(90)+10;
Write(a[i,j]:3);
if a[i,j]>a[imax,jmax] then
begin imax:=i; jmax:=j end;
end;
Writeln
end;
Writeln('Max[',imax,',',jmax,']=',a[imax,jmax])
end.
Тестовое решение
Исходный массив
76 22 34 68 78 87 98
67 76 68 10 70 63 68
78 83 88 38 89 83 88
41 70 55 59 34 37 86
48 55 86 64 98 92 59
14 47 94 74 99 15 52
35 91 31 89 31 16 91
Max[6,5]=99
Const
nc=10000;
Type
ty=array[1..nc] of real;
function minind(ar:ty;n:integer):integer;
Var
i,mini:integer;
min:real;
begin
min:=11;
for i:=1 to n do
if ar[i]<min then
begin
min:=ar[i];
mini:=i;
end;
minind:=mini;
end;
function sum1to2(ar:ty;n:integer):real;
Var
i,t1,t2:integer;
r:real;
begin
for i:=1 to n do
if ar[i]<0 then
begin
t1:=i;
break;
end;
for i:=t1+1 to n do
if ar[i]<0 then
begin
t2:=i;
break;
end;
for i:=t1+1 to t2-1 do
r:=r+ar[i];
sum1to2:=r;
end;
procedure stransort(var ar:ty;n:integer);
Var i,j,nd:integer;
begin
nd:=0;
for i:=1 to n do
if abs(ar[i])<=1 then
begin
inc(nd);
swap(ar[i],ar[nd]);
end;
end;
Var
ar:ty;
i,n:integer;
begin
randomize;
readln(n);
writeln('Array:');
for i:=1 to n do
begin
ar[i]:=random(-3,3);
write(ar[i]:4);
end;
writeln;
writeln('Index of minimum:',minind(ar,n));
writeln('Sum=',sum1to2(ar,n));
stransort(ar,n);
writeln('Final array:');
for i:=1 to n do
write(ar[i]:4);
end.
Пример ввода:
5
Пример вывода:
Array:
3 2 1 2 1
Index of minimum:3
Sum=0
Final array:
1 1 3 2 2