Pagini recente » Cod sursa (job #858126) | Cod sursa (job #2975693) | Cod sursa (job #1379359) | Cod sursa (job #1276793) | Cod sursa (job #1599491)
program potisir;
type
sir=string;
sir1=array[1..2000001] of longint;
var
a,b:sir;
f:text;
q,i,n,m:longint;
pi,pos:sir1;
begin
assign(f,'strmatch.in');
reset(f);
readln(f,a);
read(f,b);
q:=0;
n:=0;
m:=length(a);
pi[1]:=0;
for i:=2 to m do
begin
while ((q>0) and (a[q+1]<>a[i])) do
begin
q:=pi[q];
end;
if (a[q+1]=a[i]) then inc(q);
pi[i]:=q;
end;
q:=0;
for i:=1 to length(b) do
begin
while ((q>0) and (a[q+1]<>b[i]))
do
begin
q:=pi[q];
end;
if ( a[q+1]=b[i]) then q:=q+1;
if (q=m) then
begin
q:=pi[m];
n:=n+1;
if (n<=1000) then pos[n]:=i-m;
end;
end;
close(f);
assign(f,'strmatch.out');
rewrite(f);
writeln(f,n);
for i:=1 to n do write(f,pos[i],' ');
close(f);
end.