Pagini recente » Cod sursa (job #825050) | Cod sursa (job #637456) | Cod sursa (job #2519271) | Cod sursa (job #1941228) | Cod sursa (job #1109332)
Program Str ;
var a,b:string ; f:text ; i,m,n,k,c:longint ;
l,j:array[0..2000001] of longint ;
BEGIN c:=0 ;
assign(f,'strmatch.in') ; reset(F) ; readln(f,a) ; readln(f,b) ; close(f) ;
assign(f,'strmatch.out') ; rewrite(f) ;
n:=length(a) ; m:=length(b) ;
l[1]:=0 ; for i:=2 to n do if a[l[i-1]+1]=a[i] then l[i]:=l[i-1]+1 ;
k:=0 ; for i:=1 to m do begin if a[k+1]=b[i] then inc(k) else k:=0 ;
if k=n then begin inc(c) ; j[c]:=i-n ; k:=l[k] ; end ; end ;
assign(f,'strmatch.out') ; rewrite(f) ;
writeln(f,c) ;
for i:=1 to c do write(f,j[i],' ') ; close(f) ;
end .