Pagini recente » Cod sursa (job #580680) | Cod sursa (job #1904191) | Cod sursa (job #775547) | Cod sursa (job #3222397) | Cod sursa (job #1111654)
Program Str ;
var a,b:ansistring ; 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) ;
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 while (k>0) and (a[k+1]<>b[i]) do k:=l[k] ;
if a[k+1]=b[i] then inc(k) else k:=l[k] ;
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 .