program project1 mode objfpc uses IFDEF UNIX IFDEF UseCThreads cthread

 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
73
74
75
76
77
78
79
80
81
82
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
type
ar1=array[1..100,1..100] of real;
function minmax(a:ar1;n,m:integer):ar1;
var
stmin,stmax,i,j:integer;
min,max,r:real;
begin
max:=a[1,1];
stmax:=1;
for i:=1 to n do
for j:=1 to m do
if a[i,j]>max then
begin
max:=a[i,j];
stmax:=j;
end;
min:=a[1,1];
stmin:=1;
for i:=1 to n do
for j:=1 to m do
if a[i,j]<min then
begin min:=a[i,j];
stmin:=j;
end;
if stmax<stmin then
begin
for i:=1 to n do
for j:=stmax+1 to stmin do
begin
r:=a[i,j-1];
a[i,j-1]:=a[i,j];
a[i,j]:=r;
end;
end
else if stmax>stmin then
begin
for i:=1 to n do
for j:=stmax downto stmin+1 do
begin
r:=a[i,j-1];
a[i,j-1]:=a[i,j];
a[i,j]:=r;
end;
end;
minmax:=a;
end;
var
i,j,n,m:integer;
a1:ar1;
begin
readln(n,m);
writeln;
for i:=1 to n do
begin
for j:=1 to m do
begin
read(a1[i,j]);
end;
end;
writeln;
ar:minmax(a1,n,m);
for i:=1 to n do
begin
for j:=1 to m do
begin
write(a1[i,j]:0:2,'');
end;
writeln;
end;
readln;
readln;
end.