Cod sursa(job #1109333)

Utilizator WictorTTimoftii Victor WictorT Data 16 februarie 2014 23:35:47
Problema Potrivirea sirurilor Scor 14
Compilator fpc Status done
Runda Arhiva educationala Marime 0.61 kb
 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 .