Дан массив чисел, проверить для каждого числа сколько существует в списке числе меньше данного числа и давить в другой список. Вернуть массив.
Example 1:
Input: nums = [8,1,2,2,3]
Output: [4,0,1,1,3]
Explanation:
For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3).
For nums[1]=1 does not exist any smaller number than it.
For nums[2]=2 there exist one smaller number than it (1).
For nums[3]=2 there exist one smaller number than it (1).
For nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).
n = 10;
var
a: array[1..n] of integer;
i, j, t: integer;
begin
Randomize;
Writeln('Исходный массив');
for i := 1 to n do
begin
a[i] := Random(16)-10;
Write(a[i]:4)
end;
Writeln;
for i := 1 to n-1 do
for j := 1 to n-i do
if a[j] > a[j+1] then
begin t := a[j]; a[j] := a[j+1]; a[j+1] := t end;
Writeln('Отсортированный по возрастанию массив');
for i := 1 to n do Write(a[i]:4);
Writeln
end.
Тестовое решение:
Исходный массив
-10 -9 2 -3 -6 -10 -2 5 4 0
Отсортированный по возрастанию массив
-10 -10 -9 -6 -3 -2 0 2 4 5