[fpc-devel] Fwd: bug report

杨哲 yangzhe1990 at yahoo.com.cn
Sat May 21 04:10:32 CEST 2005


fpc 2.0.0 win32

problem:
  I can't see pi in proceudre pre but I can see it in procedure kmp.
  pre is a procedure belonging to kmp.
  I found that I could only see  vars in this proceudre/function and main program, but I couldn't see vars in the procedure that this procedure belongs to.
 
code:
 
var
  t,p:string;
procedure kmp(t,p:string);
  var
    n,m,q,i:integer;
    pi,match:array[1..255] of integer;
  procedure pre(p:string);
    var
      k,q:integer;
    begin
      pi[1]:=0;
      k:=0;
      for q:=2 to m do begin
        while (k>0) and (p[k+1]<>p[q]) do k:=pi[k];
        if p[k+1]=p[q] then k:=k+1;
        pi[q]:=k;
      end;
    end;
  begin
    n:=length(t);
    m:=length(p);
    q:=0;
    pre(p);
    fillchar(match,sizeof(match),0);
    for i:=1 to n do begin
      while (q>0) and (p[q+1]<>t[i]) do begin
        match[i-q]:=q;
        q:=pi[q];
      end;
      if p[q+1]=t[i] then q:=q+1;
      if q=m then begin
        match[i-q+1]:=q;
        q:=pi[q];
      end;
    end;
    write(match[1]);
    for i:=2 to n do write(' ',match[i]);
    writeln;
  end;
begin
  readln(t);
  readln(p);
  kmp(t,p);
end.



yangzhe1990 at yahoo.com.cn
                                杨哲


---------------------------------
Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂
美女明星应有尽有,搜遍美图、艳图和酷图
1G就是1000兆,雅虎电邮自助扩容!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20050521/6ab82f05/attachment.html>


More information about the fpc-devel mailing list