program lista_wspolna_z_p_i_q;
type tab=array[1..10] of integer;
lst = record
elementy: tab;
ile: integer
end;
var
i, j, k, l: integer;
p, q, r: lst; (* p i q listy niepuste i niemalejące! r - lista wynikowa *)
begin
writeln('poczatek');
read(p.ile, q.ile); readln; writeln(p.ile,' ',q.ile);
for i:= 1 to p.ile do read(p.elementy[i]);readln;
for i:= 1 to q.ile do read(q.elementy[i]);readln;
for i:= 1 to p.ile do write(p.elementy[i],' ');writeln;
for i:= 1 to q.ile do write(q.elementy[i],' ');writeln;
(*tu wpisz kod tworzenia listy r elementów wspólnych*)
r.ile := 0;
i := 1;
j := 1;
while (i <= p.ile) and (j <= q.ile) do
begin
if p.elementy[i] = q.elementy[j] then
begin
r.ile := r.ile + 1;
r.elementy[r.ile] := p.elementy[i];
i := i + 1;
j := j + 1;
end
else if p.elementy[i] < q.elementy[j] then
i := i + 1
else
j := j + 1;
end;
for i:= 1 to r.ile do write(r.elementy[i],' ');writeln;
writeln('koniec');
end.
cHJvZ3JhbSBsaXN0YV93c3BvbG5hX3pfcF9pX3E7CnR5cGUgdGFiPWFycmF5WzEuLjEwXSBvZiBpbnRlZ2VyOwogICAgIGxzdCA9IHJlY29yZAogICAgICAgICAgICAgICAgZWxlbWVudHk6IHRhYjsKICAgICAgICAgICAgICAgIGlsZTogaW50ZWdlcgogICAgICAgICAgICAgZW5kOwp2YXIKICAgIGksIGosIGssIGw6IGludGVnZXI7CiAgICBwLCBxLCByOiBsc3Q7ICAoKiAgcCBpIHEgbGlzdHkgbmllcHVzdGUgaSBuaWVtYWxlasSFY2UhIHIgLSBsaXN0YSB3eW5pa293YSAqKQogICAgCmJlZ2luCiAgICB3cml0ZWxuKCdwb2N6YXRlaycpOwogICAgcmVhZChwLmlsZSwgcS5pbGUpOyByZWFkbG47IHdyaXRlbG4ocC5pbGUsJyAnLHEuaWxlKTsKICAgIGZvciBpOj0gMSB0byBwLmlsZSBkbyByZWFkKHAuZWxlbWVudHlbaV0pO3JlYWRsbjsKICAg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