Cod sursa(job #713905)

Utilizator MegyesiMegyesi Attila Megyesi Data 15 martie 2012 09:35:09
Problema Potrivirea sirurilor Scor 38
Compilator fpc Status done
Runda Arhiva educationala Marime 0.69 kb
var x,y:array[1..2000000] of char;
    f,g:text;
    k,db,n,m,i,j:longint;
    r:Array[1..1000] of integer;
    ok:boolean;


begin
 assign(f,'strmatch.in');
 assign(g,'strmatch.out');
 reset(f);
 rewrite(g);
 m:=0;
 n:=0;
 while not eoln(f) do
  begin
   inc(m);
   read(f,y[m]);
  end;
  readln(f);
 while not eoln(f) do
  begin
   inc(n);
   read(f,x[n]);
  end;
 for i:=1 to n-m do if x[i]=y[1] then
 begin
 k:=i;
 ok:=true;
 for j:=i to i+m-1 do if x[j]<>y[j-k+1] then ok:=false;
 if ok then begin
             inc(db);
             if db<1000 then r[db]:=i;
            end;
 end;
 writeln(g,dB);
 for i:=1 to db do write(g,r[i]-1,' ');

 close(f);
 close(g);
end.