22 lines
592 B
C++
22 lines
592 B
C++
#include <iostream>
|
||
#include <string>
|
||
using namespace std;
|
||
|
||
void build(string& _pre, string& _in, int pre_front, int pre_end, int in_front, int in_end){
|
||
if (pre_front > pre_end) return;
|
||
|
||
char root;
|
||
root = _pre[pre_front];
|
||
int k = _in.find(root, in_front);//´Óin_front¿ªÊ¼
|
||
int leftsize = k - in_front;
|
||
build(_pre, _in, pre_front + 1, pre_front + leftsize, in_front, k - 1);
|
||
build(_pre, _in, pre_front + leftsize + 1 , pre_end, k + 1, in_end);
|
||
cout << root << " ";
|
||
}
|
||
int main(){
|
||
string pre, in;
|
||
cin >> pre >> in;
|
||
build(pre, in, 0, pre.size() - 1, 0, in.size() - 1);
|
||
return 0;
|
||
}
|