Pagini recente » Cod sursa (job #1140038) | Cod sursa (job #141833) | Cod sursa (job #3177742) | Cod sursa (job #1415042) | Cod sursa (job #360755)
Cod sursa(job #360755)
Program seti;
var r : integer;
v : array[1..1500] of integer;
f,g : text;
A,B : string;
Procedure urmatorul(p : string);
var k,q : integer;
begin
k:=0;
urm[1]:=0;
for q:=2 to length(p) do
while (k>0) and (p[k+1]<>p[q]) do k:=urm[k];
if p[k+1]=p[q] then inc(k);
urm[q]:=k;
end;
end.
Procedure KMP(T,P : string);
var j,q,i,m : longint;
begin
j:=1;
q:=0;
m:=length(P);
urmatorul(P);
for i:=1 to length(T) do
begin
while (q>0) and (P[q+1]<>T[i]) q:=urm(q);
if P[q+1]=T[i] then inc(q);
if q=length(p) then
begin
inc(r);
v[j]:=i-m+1;
inc(j);
if j>1000 then j:=1001;
q:=urm(q);
end;
end;
begin
assign(f,'strmatch.in');
reset(f);
readln(f,A);
readln(f,B);
KMP(B,A);
close(f);
assign(g,'strmatch.out');
rewrite(g);
writeln(g,r);
if j=1001 then for l:=1 to 1000 do write(g,v[l],' ') else
for l:=1 to j do
write(g,v[l],' ');
close(g);
end.