Pagini recente » Cod sursa (job #2103044) | Cod sursa (job #1427239) | Cod sursa (job #155469) | Cod sursa (job #169715) | Cod sursa (job #1219818)
var
s, p : ansistring;
l : array[1..2000000] of longint;
k, i, u, w, h: longint;
q : array[1..1000] of longint;
begin
assign(input,'strmatch.in');
reset(input);
assign(output,'strmatch.out');
rewrite(output);
readln(p);
readln(s);
l[1]:=0; w:=length(p);
for i:=2 to w do
begin
k:=l[i-1];
while (k>0) and (p[k+1]<>p[i]) do
k:=l[k];
if p[k+1]=p[i] then
inc(k);
l[i]:=k;
end;
k:=0;
h:=length(s);
for i:=1 to h do
begin
while (k>0) and (p[k+1]<>s[i]) do
k:=l[k];
if p[k+1]=s[i] then
inc(k);
if k=length(p) then
begin
inc(u);
if u<1000 then
q[u]:=i-w;
k:=l[k];
end;
end;
writeln(u);
if u>1000 then
for i:=1 to 1000 do
write(q[i],' ')
else
for i:=1 to u do
write(q[i],' ');
Close(output);
end.