Pagini recente » Cod sursa (job #713110) | Istoria paginii utilizator/teodoraxinte | Clasament sim1robert | Cod sursa (job #132392) | Cod sursa (job #291364)
Cod sursa(job #291364)
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 me;
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
inc(nr);
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);
me;
end.