Глава 52. Задание "Г".
Добавлено: 13.12.2016 12:00:35
Прошу оценить мое решение:
- Код: Выделить всё
const CSize = 255;
type TSet = set of 1..CSize;
var S : TSet;
i, n1, n2, k : integer;
begin
S := [];
for i := 1 to CSize do begin
k := Random(CSize) + 1;
S:= S + [k];
end;
for i := 1 to CSize do
if i in S then Writeln(i);
k := 1;
Write('[');
repeat
if (k in S) and ((k + 1) in S) and ((k + 2) in S)
then begin
n1 := k;
while k in S do Inc(k);
n2 := k - 1;
Write(n1, '..', n2, ', ');
end
else
if (k in S) and ((k + 1) in S) and not ((k + 2) in S)
then begin
Write(k, ', ');
Inc(k);
end
else
if (k in S) and not ((k + 1) in S)
then begin
Write(k, ', ');
Inc(k);
end
else if not (k in S)
then Inc(k);
until (k > (CSize));
Write(']');
REadln;
end.