Решите задачу для следующих наборов входных данных: p = 1, k = 1, a = -100, program [1]
p = -10, k = 1, a = 100, program [1]
p = 1, k = 10, a = 100, program [2]
p = 1, k = -10, a = -10, program [2]
p = -10, k = 10, a = 10, program [1,2]
p = 10, k = -10, a = 10, program [1,2]
p = -10, k = 10, a = 10, program [2,1]
p = -10, k = -10, a = 1, program [1,2,1]
p = -5, k = 5, a = 5, program [2,1,2]
p = -1, k = 3, a = 1, program [2,1,2]
p = 1, k = 2, a = 3, program [1,2,2,1]
p = 9, k = 1, a = 8, program [1,1,1,1,1,1,1,1,1,1]
p = -10, k = 1, a = 10, program [1,1,1,1,1]
p = -10, k = 5, a = -86, program [1,1,1,1,1,1,1,1,1,1]
p = 1, k = 6, a = 5, program [2,2,2,2,2,2,2,2,2,2]
p = 1, k = -10, a = 96, program [2,2,2,2,2,2,2,2,2,1]
p = 1, k = -9, a = -100, program [2,2,2,2,2,2,2,2,2,2]
p = -10, k = 10, a = 97, program [1,2,1,2,1,2,1,2,1,2]
p = -10, k = -10, a = 84, program [1,1,1,1,1,2,2,2,2,2]
p = -10, k = -10, a = 100, program [2,2,2,2,2,1,1,1,1,1]
Отправьте на проверку текстовый файл с результатами для каждого набора данных
nn = 20;
type
ta = array[1..nn] of integer;
procedure FillArray(var a: ta; n, min, max: integer);
var
i, k: integer;
begin
k := max - min + 1;
for i := 1 to n do a[i] := Random(k) + min
end;
procedure WriteArray(a: ta; n, p: integer);
var
i: integer;
begin
for i := 1 to n do Write(a[i]:p);
Writeln
end;
procedure CopyNegative(var a, b: ta; m: integer; var n: integer);
var
i: integer;
begin
n := 0;
for i := 1 to m do
if a[i] < 0 then
begin
Inc(n);
b[n] := a[i]
end
end;
var
n: integer;
x, y: ta;
begin
Randomize;
FillArray(x, 10, -50, 50);
Writeln('Исходный массив');
WriteArray(x, 10, 4);
CopyNegative(x, y, 10, n);
Writeln('Массив из отрицательных элементов');
WriteArray(y, n, 4);
FillArray(x, 8, -200, 100);
Writeln('Исходный массив');
WriteArray(x, 12, 5);
CopyNegative(x, y, 12, n);
Writeln('Массив из отрицательных элементов');
WriteArray(y, n, 5);
end.
Тестовое решение:
Исходный массив
-12 17 35 -4 -45 8 33 -8 -47 -4
Массив из отрицательных элементов
-12 -4 -45 -8 -47 -4
Исходный массив
-150 -174 92 -168 69 -60 -165 -78 -47 -4 0 0
Массив из отрицательных элементов
-150 -174 -168 -60 -165 -78 -47 -4