/* * tree03.cpp * * Created on: Apr 12, 2024 * Author: 28032 */ //建树 /*#include #include #include #include using namespace std; struct Note { Note(int val) { value = val; left = NULL; right = NULL; } char value; Note* left; Note* right; }; string front,middle; set exist; Note* reBuildTree(unsigned int f_index,int m_l,int m_r) { char rootValue = front[f_index]; while(exist.count(rootValue)&&f_index 1) root->left = reBuildTree(f_index+1,m_l,m_index-1); else if(L.size() == 1) { exist.insert(L[0]); root->left = new Note(L[0]); } else root->left = NULL; string R = middle.substr(m_index+1,m_r-m_index); if(R.size() > 1) root->right = reBuildTree(f_index+1,m_index+1,m_r); else if(R.size() == 1) { exist.insert(R[0]); root->right = new Note(R[0]); } else root->right = NULL; return root; } void backVisit(Note* root) { if(root == NULL) return ; backVisit(root->left); backVisit(root->right); cout<value; } int main() { while(1) { int n = 0; cin>>n; if(!n) break; cin>>front>>middle; exist.clear(); Note* root = reBuildTree(0,0,n-1); backVisit(root); cout<