-
Notifications
You must be signed in to change notification settings - Fork 8
/
S114.pas
51 lines (51 loc) · 893 Bytes
/
S114.pas
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
var
a, b: array[0..1000] of longint;
n, c, i, j, t: longint;
begin
read(n, c);
for i := 1 to n do
read(a[i]);
for i := n - 1 downto 1 do
for j := 1 to i do
if (a[j] > a[j + 1]) then
begin
t := a[j];
a[j] := a[j + 1];
a[j + 1] := t
end;
if (n mod 2 = 1) then
begin
i := 1;
while (i <= n) do
begin
b[i] := a[i];
i := i + 2
end;
i := 2;
while (i <= n) do
begin
b[i] := a[n - i + 1];
i := i + 2
end
end
else
begin
for i := 1 to n div 2 do
begin
if (i mod 2 = 1) then
b[i] := a[i]
else
b[n - i + 1] := a[i]
end;
for i := n div 2 + 1 to n do
begin
if (i mod 2 = 1) then
b[i + 1] := a[i]
else
b[n - i + 2] := a[i]
end;
end;
for i := 1 to n - 1 do
write(b[i], ' ');
writeln(b[n])
end.