Pagini recente » Cod sursa (job #2716069) | Cod sursa (job #1677909) | Cod sursa (job #2921540) | Cod sursa (job #1729439) | Cod sursa (job #289533)
Cod sursa(job #289533)
var solutii,m,n:longint;
a,b:array[0..2000005] of char;
pi:array[0..2000005] of longint;
pos:array[1..1024] of longint;
procedure make_prefix;
var i,q:longint;
begin
q:=0;
pi[1]:=0;
for i:=2 to m do
begin
while (q<>0) and (a[q+1] <> a[i]) do q:=pi[q];
if A[q+1] = A[i] then q:=q+1;
pi[i]:=q;
end;
end;
procedure Citeste;
var f:text;
i,q:longint;
begin
assign(f,'strmatch.in');
reset(f);
m:=1;n:=1;
while not eoln(f) do
begin
read(f,a[m]);
m:=m+1;
end;
m:=m-1;
a[0]:=' ';b[0]:=' ';
make_prefix;
readln(f);
q:=0;
solutii:=0;
i:=1;
while not eoln(f) do
begin
read(f,b[i]);
while (q<>0) and (a[q+1] <> b[i]) do q := pi[q];
if (A[q+1] = b[i]) then q:=q+1;
if (q=M) then
begin
q:=pi[m];
solutii:=solutii+1;
if (solutii <= 1000) then pos[solutii] := i-m;
end;
i:=i+1;
end;
close(f);
end;
procedure Scrie;
var i,min:longint;
f:text;
begin
if solutii<1000 then min:=solutii
else min:=1000;
assign(f,'strmatch.out');
rewrite(f);
writeln(f,solutii);
for i:=1 to min do
begin
write(f,pos[i],' ');
end;
close(f);
end;
begin
Citeste;
Scrie;
end.