Pagini recente » Cod sursa (job #249370) | Cod sursa (job #551737) | Cod sursa (job #2826744) | Cod sursa (job #1821448) | Cod sursa (job #277112)
Cod sursa(job #277112)
program pascal;
var f,g:text; a,b:ansistring; p:array[1..2000000] of longint;
sol:array[1..1001] of longint;
i,n,m:longint; nr,k:int64;
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.