Pagini recente » Cod sursa (job #2519604) | Cod sursa (job #1332445) | Cod sursa (job #1375880) | Cod sursa (job #1345810) | Cod sursa (job #593150)
Cod sursa(job #593150)
var a,b:array[1..2000000] of char;
c:array[1..2000000] of longint;
v:array[1..1000] of longint;
n,nr,m,i,k:longint;
begin
assign(input,'strmatch.in');reset(input);
assign(output,'strmatch.out');rewrite(output);
n:=0;nr:=0;
while not seekeoln(input) do
begin
inc(n);
read(a[n]);
end;
m:=0;readln;
while not seekeoln(input) do
begin
inc(m);
read(b[m]);
end;
k:=0;
for i:=2 to n do
begin
while (k>0) and (a[k+1]<>a[i]) do k:=c[k];
if a[k+1]=a[i] then inc(k);
c[i]:=k;
end;
k:=0;
for i:=1 to m do
begin
while (k>0) and (a[k+1]<>b[i]) do k:=c[k];
if a[k+1]=b[i] then inc(k);
if k=n then
begin
inc(nr);
if nr<=1000 then v[nr]:=i-n;
end;
end;
writeln(nr);
if nr>1000 then nr:=1000;
for i:=1 to nr do write(v[i],' ');
close(output);
end.