Cod sursa(job #593151)

Utilizator tibi9876Marin Tiberiu tibi9876 Data 1 iunie 2011 15:44:07
Problema Potrivirea sirurilor Scor 60
Compilator fpc Status done
Runda Arhiva educationala Marime 0.78 kb
var a,b:array[1..2000000] of char;
    c:array[1..2000000] of word;
    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.