Cod sursa(job #192972)

Utilizator GavrilaVladGavrila Vlad GavrilaVlad Data 1 iunie 2008 19:40:14
Problema Potrivirea sirurilor Scor 14
Compilator fpc Status done
Runda Arhiva educationala Marime 1.66 kb
var a,b:ansistring;
    v:array[1..1000]of longint;
    n,nr,i,j,k,l,o,p:longint;
    h,z:int64;
    f:text;
begin
   assign(f,'strmatch.in');
   reset(f);
   readln(f,a);
   readln(f,b);
   close(f);
   k:=length(a);
   n:=length(b);
   z:=67;
   p:=z;
   for i:=1 to k-1 do
     begin
       p:=p*z;
       if(a[i] in ['0'..'9'])then l:=48
                             else
       if(a[i] in ['A'..'B'])then l:=55
                             else l:=61;
       h:=h*z+ord(a[i])-l;
       if(b[i] in ['0'..'9'])then l:=48
                             else
       if(b[i] in ['A'..'B'])then l:=55
                             else l:=61;
       o:=o*z+ord(b[i])-l;
     end;
   if(a[k] in ['0'..'9'])then l:=48
                         else
   if(a[k] in ['A'..'B'])then l:=55
                         else l:=61;
   h:=h*z+ord(a[k])-l;
   for i:=k to n do
     begin
       if(b[i] in ['0'..'9'])then l:=48
                             else
       if(b[i] in ['A'..'B'])then l:=55
                             else l:=61;
       o:=o*z+ord(b[i])-l;
       if(i>k)then begin if(b[i-k] in ['0'..'9'])then l:=48
                                                 else
                         if(b[i-k] in ['A'..'B'])then l:=55
                                                 else l:=61;
                         o:=o-(ord(b[i-k])-l)*p;
                   end;
       if(o=h)and(nr<1000)then begin nr:=nr+1;
                                     v[nr]:=i-k;
                               end;
     end;
   assign(f,'strmatch.out');
   rewrite(f);
   writeln(f,nr);
   for i:=1 to nr do
   write(f,v[i],' ');
   writeln(f);
   close(f);
end.