Pagini recente » Cod sursa (job #53298) | Cod sursa (job #877489) | Cod sursa (job #2968855) | Cod sursa (job #3173520) | Cod sursa (job #537140)
Cod sursa(job #537140)
program STRMATCH;
type vect=array[0..2000002]of char;
var f,g:text;n,m,i,k,x,nr:longint;ch:char;
p,t:vect;
l,poz:array[0..2000002]of longint;
procedure urmatorul(var p:vect);
var k,i:longint;
begin
k:=-1;
l[0]:=0;
for i:=1 to m-1 do begin
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;
end;
begin
assign(f,'strmatch.in');reset(f);
assign(g,'strmatch.out');rewrite(g);
k:=0;
read(f,ch);
while (ord(ch)>=65)and(ord(ch)<=90) do begin
p[m]:=ch;
read(f,ch);
inc(m);
end;
read(f,ch);
read(f,ch);
while (ord(ch)>=65)and(ord(ch)<=90) do begin
t[n]:=ch;
read(f,ch);
inc(n);
end;
urmatorul(p);
for i:=0 to n-1 do begin
while (x>0)and(p[x+1]<>t[i]) do x:=l[x];
if p[x+1]=t[i] then inc(x);
if (x=m-1) then begin
if nr>1000 then break;
inc(nr);
poz[nr]:=i-m+1;
x:=l[x];
end;
end;
writeln(g,nr);
for i:=1 to nr do write(g,poz[i],' ');
CLOSE(F);close(g);
end.