已知树的前序遍历和中序遍历,求后序遍历,这个没什么好说的了,我是先建树(虽然不建树也可以把..)
{
ID:lucky141
PROG:heritage
LANG:PASCAL
}
program heritage;
var
s1,s2:string;
tree:array[1..700] of char;
procedure buildtree(l,r,num,k:integer);
var
i,j:integer;
begin
if r<l then exit;
tree[num]:=s2[k];
i:=pos(s2[k],s1);
if l<>r then
begin
buildtree(l,i-1,num*2,k+1);
buildtree(i+1,r,num*2+1,k+i-l+1);
end;
end;
procedure print(num:integer);
begin
if ('A'<=tree[num*2]) and (tree[num*2]<='Z') then print(num*2);
if ('A'<=tree[num*2+1]) and (tree[num*2+1]<='Z') then print(num*2+1);
write(tree[num]);
end;
begin
assign(input,'heritage.in');
reset(input);
assign(output,'heritage.out');
rewrite(output);
readln(s1);
readln(s2);
buildtree(1,length(s1),1,1);
print(1);
writeln;
close(input);
close(output);
end.