Tree(uva 536)

时间:2023-03-08 23:20:13
Tree(uva 536)

先声明,我还在学习中,这个题大部分代码借鉴的大佬的,其实这算是比较经典二叉树题了,关键在于递归建树。

代码附上:

 #include <iostream>
#include <cstring> using namespace std; char TF[];
char TM[]; void TL( int p1, int p2, int q1, int q2, int root )
{
if ( p1 > p2 ) return;
for ( root = q1 ; TM[root] != TF[p1] ; ++ root );
TL( p1+, p1+root-q1, q1, root-, );
TL( p1+root-q1+, p2, root+, q2, );
cout << TM[root];
} int main()
{
while ( cin >> TF >> TM ) {
int L = strlen(TF)-;
TL( , L, , L, );
cout << endl;
}
return ;
}