Pagini recente » Cod sursa (job #2409697) | Cod sursa (job #881219) | Cod sursa (job #1860290) | Cod sursa (job #33783) | Cod sursa (job #277094)
Cod sursa(job #277094)
program pascal;
var f,g:text; a,b:string; p:array[1..2000000] of integer;
sol:array[1..1001] of integer;
nr,i,j,k,n,m:longint;
procedure citire;
begin
assign(f,'strmatch.in'); reset(f);
assign(g,'strmatch.out'); rewrite(g);
readln(f,a);
read(f,b);
close(f);
end;
procedure paul;
begin
p[1]:=0;
k:=0;
for i:=2 to n do
begin
while (k>0) and (a[k+1]<>a[i]) do k:=p[k];
if a[k+1]=a[i] then k:=k+1;
p[i]:=k;
end;
k:=0;
for i:=1 to m do
begin
while (k>0) and (a[k+1]<>b[i]) do k:=p[k];
if (a[k+1]=b[i]) then k:=k+1;
if k=n then
begin
nr:=nr+1;
if (nr<=1000) then sol[nr]:=i-n;
k:=p[k];
end;
end;
writeln(g,nr);
if (nr>1000) then nr:=1000;
for i:=1 to nr do write(g,sol[i],' ');
close(g);
end;
begin
citire;
n:=length(a);
m:=length(b);
paul;
end.