首页 > 代码库 > POJ 2255-Tree Recovery

POJ 2255-Tree Recovery

题意:

       树的前,中序遍历求后序遍历。基础题。

 

 

 

 

 


 

code

#include <iostream>#include <string>using namespace std;string sq, sh;int len;void make (int l, int r, int t, int w) {	if (l > r || t > w) return;	char s = sq[l];	int i;	for (i = 0; i < len; i++) if (sh[i] == s) break;	int k = i - t;	make (l + 1, l + k, t, i - 1);	make (l + k + 1, r, i+1, w);	cout << s;}int main() {	while (cin >> sq >> sh) {		len = (int) sq.size() - 1;		make (0, len, 0, len);		cout << endl;	}	return 0;}

  

POJ 2255-Tree Recovery