|
P.54.2.
Program E_2_2_1;
uses crt, dos;
var
f : text;
k, m, a : integer;
Mass : array[0..10] of integer;
begin
assign(f,'e:\test_in.txt'); reset(f);
for k:=1 to 10 do readln(f,Mass[k]);
close(f);
for k:=2 to 10 do begin
a:=Mass[k]; Mass[0]:=a; m:=k;
while a
Mass[m]:=Mass[m-1]; m:=m-1;
end;
Mass[m]:=a;
end;
assign(f,'e:\test_out.txt'); rewrite(f);
for k:=1 to 10 do writeln(f,Mass[k]);
close(f);
end.
P.54.3.
Program E_2_2_2;
uses crt, dos;
var
f : text;
k, m, a : integer;
Mass : array[1..11] of integer;
begin
assign(f,'e:\test_in.txt'); reset(f);
for k:=1 to 10 do readln(f,Mass[k]);
close(f);
for k:=9 downto 1 do begin
a:=Mass[k]; Mass[11]:=a; m:=k;
while a
Mass[m]:=Mass[m+1]; m:=m+1;
end;
Mass[m]:=a;
end;
assign(f,'e:\test_out.txt'); rewrite(f);
for k:=1 to 10 do writeln(f,Mass[k]);
close(f);
end.
P.54.4.
Program E_2_2_3;
uses crt, dos;
var
f : text;
k, m, a : integer;
Mass : array[1..10] of integer;
begin
assign(f,'e:\test_in.txt'); reset(f);
for k:=1 to 10 do readln(f,Mass[k]);
close(f);
for k:=10 downto 2 do
for m:=2 to k do
if Mass[m-1]>Mass[m] then begin
a:=Mass[m-1];
Mass[m-1]:=Mass[m];
Mass[m]:=a
end;
assign(f,'e:\test_out.txt'); rewrite(f);
for k:=1 to 10 do writeln(f,Mass[k]);
close(f);
end.
P.54.5.
Program E_2_2_4;
uses crt, dos;
var
f : text;
k, m, a : integer;
Mass : array[1..10] of integer;
begin
assign(f,'e:\test_in.txt'); reset(f);
for k:=1 to 10 do readln(f,Mass[k]);
close(f);
for k:=1 to 9 do
for m:=9 downto k do
if Mass[m+1]
a:=Mass[m+1];
Mass[m+1]:=Mass[m];
Mass[m]:=a
end;
assign(f,'e:\test_out.txt'); rewrite(f);
for k:=1 to 10 do writeln(f,Mass[k]);
close(f);
end.
P.54.6.
Program E_2_2_5;
uses crt, dos;
var
f : text;
k, m, a : integer;
Mass : array[1..10] of integer;
begin
assign(f,'e:\test_in.txt'); reset(f);
for k:=1 to 10 do readln(f,Mass[k]);
close(f);
for k:=1 to 9 do
for m:=9 downto k do
if Mass[m+1]>Mass[m] then begin
a:=Mass[m+1];
Mass[m+1]:=Mass[m];
Mass[m]:=a
end;
assign(f,'e:\test_out.txt'); rewrite(f);
for k:=1 to 10 do writeln(f,Mass[k]);
close(f);
end.
P.54.7.
Program E_2_2_6;
uses crt, dos;
var
f : text;
k, m, a : integer;
Mass : array[1..10] of integer;
begin
assign(f,'e:\test_in.txt'); reset(f);
for k:=1 to 10 do readln(f,Mass[k]);
close(f);
for k:=10 downto 2 do
for m:=2 to k do
if Mass[m-1]
a:=Mass[m-1];
Mass[m-1]:=Mass[m];
Mass[m]:=a
end;
assign(f,'e:\test_out.txt'); rewrite(f);
for k:=1 to 10 do writeln(f,Mass[k]);
close(f);
end.
P.54.8.
Program E_2_2_7;
uses crt, dos;
var
f : text;
k, m, a, Left, Right : integer;
Mass : array[1..10] of integer;
Pr : boolean;
begin
assign(f,'e:\test_in.txt'); reset(f);
for k:=1 to 10 do readln(f,Mass[k]);
close(f);
Pr:=true; Left:=1; Right:=10;
while Pr do begin
Pr:=false;
for k:=Left+1 to Right do
if Mass[k-1]>Mass[k] then begin
a:=Mass[k-1];
Mass[k-1]:=Mass[k];
Mass[k]:=a;
Pr:=true;
end;
for k:=Right-1 downto Left do
if Mass[k+1]
a:=Mass[k+1];
Mass[k+1]:=Mass[k];
Mass[k]:=a;
Pr:=true;
end;
Left:=Left+1;
Right:=Right-1;
end;
assign(f,'e:\test_out.txt'); rewrite(f);
for k:=1 to 10 do writeln(f,Mass[k]);
close(f);
end.
P.54.9.
Program E_2_2_8;
uses crt, dos;
var
f : text;
k, m, a, Left, Right : integer;
Mass : array[1..10] of integer;
Pr : boolean;
begin
assign(f,'e:\test_in.txt'); reset(f);
for k:=1 to 10 do readln(f,Mass[k]);
close(f);
Pr:=true; Left:=1; Right:=10;
while Pr do begin
Pr:=false;
for k:=Left+1 to Right do
if Mass[k-1]
a:=Mass[k-1];
Mass[k-1]:=Mass[k];
Mass[k]:=a;
Pr:=true;
end;
for k:=Right-1 downto Left do
if Mass[k+1]>Mass[k] then begin
a:=Mass[k+1];
Mass[k+1]:=Mass[k];
Mass[k]:=a;
Pr:=true;
end;
Left:=Left+1;
Right:=Right-1;
end;
assign(f,'e:\test_out.txt'); rewrite(f);
for k:=1 to 10 do writeln(f,Mass[k]);
close(f);
end.
|