<DIV>
<DIV>fpc 2.0.0 win32</DIV><BR>
<DIV>problem:</DIV>
<DIV>  I can't see pi in proceudre pre but I can see it in procedure kmp.</DIV>
<DIV>  pre is a procedure belonging to kmp.</DIV>
<DIV>  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.</DIV>
<DIV> </DIV>
<DIV>code:</DIV>
<DIV> </DIV>
<DIV>var<BR>  t,p:string;<BR>procedure kmp(t,p:string);<BR>  var<BR>    n,m,q,i:integer;<BR>    pi,match:array[1..255] of integer;<BR>  procedure pre(p:string);<BR>    var<BR>      k,q:integer;<BR>    begin<BR>      pi[1]:=0;<BR>      k:=0;<BR>      for q:=2 to m do begin<BR>        while (k>0) and (p[k+1]<>p[q]) do k:=pi[k];<BR>        if p[k+1]=p[q] then k:=k+1;<BR>        pi[q]:=k;<BR>      end;<BR>    end;<BR>  begin<BR>    n:=length(t);<BR>    m:=length(p);<BR>    q:=0;<BR>    pre(p);<BR>    fillchar(match,sizeof(match),0);<BR>    for i:=1 to n do
 begin<BR>      while (q>0) and (p[q+1]<>t[i]) do begin<BR>        match[i-q]:=q;<BR>        q:=pi[q];<BR>      end;<BR>      if p[q+1]=t[i] then q:=q+1;<BR>      if q=m then begin<BR>        match[i-q+1]:=q;<BR>        q:=pi[q];<BR>      end;<BR>    end;<BR>    write(match[1]);<BR>    for i:=2 to n do write(' ',match[i]);<BR>    writeln;<BR>  end;<BR>begin<BR>  readln(t);<BR>  readln(p);<BR>  kmp(t,p);<BR>end.</DIV></DIV><BR><BR>yangzhe1990@yahoo.com.cn<br>                                杨哲<p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="http://music.yisou.com" target=blank>150万曲MP3疯狂搜,带您闯入音乐殿堂</a><br><a href="http://image.yisou.com" target=blank>美女明星应有尽有,搜遍美图、艳图和酷图</a><br>
<a href="http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/" target=blank>1G就是1000兆,雅虎电邮自助扩容!</a>