Pagini recente » Cod sursa (job #817648) | Cod sursa (job #249239) | Cod sursa (job #1485048) | Cod sursa (job #309438) | Cod sursa (job #709879)
Cod sursa(job #709879)
Program strmatch_arena_edu;
var fi,fo : text; i,m,n,k,nrsol : longint;
a,b : array[1..2000001] of char; r:set of char;
sol:array[0..1010] of longint; pi:array[0..2000000] of longint;
begin
assign(fi,'strmatch.in'); reset(fi);
assign(fo,'strmatch.out'); rewrite(fo);
pi[1]:=0; k:=0; m:=1; n:=1; r:=['A'..'Z']+['a'..'z']+['0'..'9'];
readln(fi,a); read(fi); readln(fi,b);
while a[m] in r do m:=m+1;
while b[n] in r do n:=n+1;
m:=m-1; n:=n-1;
for i:=2 to m do begin
while (k>0) and (a[k+1]<>a[i]) do k:=pi[k];
if a[k+1]=a[i] then k:=k+1;
pi[i]:=k;
end;
k:=0;
for i:=1 to n do begin
while (k>0) and (a[k+1]<>b[i]) do k:=pi[k];
if a[k+1]=b[i] then k:=k+1;
if k=m then begin
k:=pi[m];
nrsol:=nrsol+1;
if nrsol<=1000 then sol[nrsol]:=i-m;
end;
end;
writeln(fo,nrsol);
if nrsol>1000 then nrsol:=1000;
for i:=1 to nrsol do write(fo,sol[i],' ');
close(fi); close(fo);
end.