begin var a := ArrRandom(ReadInteger('n='), -50, 50);a.Println; var b := a.IndexesOf(t -> t.IsEven).ToArray; var b1 := a.Where(t -> t.IsEven).Sorted.ToArray; var b2 := ArrFill(a.Length, 1); if b.Length < 0 then begin a.Println; exit; end; for var i := 0 to b.Length - 1 do b2[b[i]] := b1[i]; for var i := 0 to a.Length - 1 do if b2[i].IsOdd then b2[i] := a[i]; b2.Println; end.
//Версия 3.3, сборка 1634 (14.02.2018)
begin
var a := ArrRandom(ReadInteger('n='), -50, 50);a.Println;
var b := a.IndexesOf(t -> t.IsEven).ToArray;
var b1 := a.Where(t -> t.IsEven).Sorted.ToArray;
var b2 := ArrFill(a.Length, 1);
if b.Length < 0 then begin a.Println; exit; end;
for var i := 0 to b.Length - 1 do b2[b[i]] := b1[i];
for var i := 0 to a.Length - 1 do if b2[i].IsOdd then b2[i] := a[i];
b2.Println;
end.
Пример:
n= 10
30 9 27 25 -34 25 -5 5 46 -46
-46 9 27 25 -34 25 -5 5 30 46