【UVA】536 Tree Recovery(树型结构基础)

题目

题目
 


 

分析

莫名A了
 


 

代码

#include <bits/stdc++.h>
using namespace std;
string s1,s2;
void build(int l1,int r1,int l2,int r2)
{
	int root=l1,p=l2;
	if(l1>r1) return;
	while(s2[p]!=s1[root] && p<=r2) p++;
	int cnt=p-l2;
	build(l1+1,l1+cnt,l2,p-1);
	build(l1+cnt+1,r1,p+1,r2);
	printf("%c",s1[root]);
}
int main()
{
	while(cin>>s1>>s2)
	{
		build(0,s1.length()-1,0,s2.length()-1);
		puts("");
	}
	return 0;
}
posted @ 2017-12-03 17:57  noble_(noblex)  阅读(216)  评论(0编辑  收藏  举报
/* */