这是第十四届全国青少年信息学奥林匹克竞赛的最后一题程序阅读题,我看了好久都没看懂
最大的疑问就是solve过程中的两个自我引用,第一个solve执行到什么时候会跳出执行第二个solve,又是何时跳出执行write的呢?希望高手能给出详细的解析过程!谢谢...
最大的疑问就是solve过程中的两个自我引用,第一个solve执行到什么时候会跳出执行第二个solve,又是何时跳出执行write的呢?希望高手能给出详细的解析过程!谢谢!!
procedure solve(first:string;spos_f,epos_f:integer;mid:string;spos_m,epos_m:integer);
var i,root_m:integer;
begin
if spos_f > epos_f then exit;
for i:=spos_m to epos_m do
if first[spos_f]=mid[i] then begin
root_m:=i;
break;
end;
solve(first,spos_f+1,spos_f+(root_m-spos_m),mid,spos_m,root_m-1);
solve(first,spos_f+(root_m-spos_m)+1,epos_f,mid,root_m+1,epos_m);
write(first[spos_f]);
end;
var first,mid:string;
len:integer;
begin
readln(len);
readln(first);
readln(mid);
solve(first,1,len,mid,1,len);
writeln;
end.
输入:7
ABDCEGF
BDAGECF
输出:_________________________________ 展开
procedure solve(first:string;spos_f,epos_f:integer;mid:string;spos_m,epos_m:integer);
var i,root_m:integer;
begin
if spos_f > epos_f then exit;
for i:=spos_m to epos_m do
if first[spos_f]=mid[i] then begin
root_m:=i;
break;
end;
solve(first,spos_f+1,spos_f+(root_m-spos_m),mid,spos_m,root_m-1);
solve(first,spos_f+(root_m-spos_m)+1,epos_f,mid,root_m+1,epos_m);
write(first[spos_f]);
end;
var first,mid:string;
len:integer;
begin
readln(len);
readln(first);
readln(mid);
solve(first,1,len,mid,1,len);
writeln;
end.
输入:7
ABDCEGF
BDAGECF
输出:_________________________________ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询