欢迎使用本站,预祝练习时长两年半的选手们到成功! [本模块信息来自tem/def/head]

1364:二叉树遍历

时间:2024-05-05 12:56 作者:admin 点击:
#include iostreamusing namespace std;string a,b;void f(string cx,string zx){if(zx.size()==0) return ;char root=cx[0];int rootid=zx.find(root);string lzx=zx.substr(0,rootid);string rzx=zx.substr(rootid+1);string lcx="",rcx="";for(int i=1;cx[
#include <iostream>
using namespace std;
string a,b;
void f(string cx,string zx){
	if(zx.size()==0) return ;
	char root=cx[0];
	int rootid=zx.find(root);
	string lzx=zx.substr(0,rootid);
	string rzx=zx.substr(rootid+1);
	string lcx="",rcx="";
	for(int i=1;cx[i];i++){
		int d=lzx.find(cx[i]);
		if(d!=-1) lcx+=cx[i];
		else rcx+=cx[i];
	}
	cout<<root;
	f(lcx,lzx);
	f(rcx,rzx);
}
int main(){
	cin>>b>>a;
	f(a,b);
	return 0;
}


(责任编辑:admin)
    顶一下
    (0)
    0%
    踩一下
    (0)
    0%