题解,但需自己填写!!!hahaha

吴晨曦  •  6个月前


American Herritage

本题考查:二叉树的概念与其遍历

首先,先输入两个字符串。
肯定的,用分治最好。
再分成几个部分进行处理即可
此处用work(pre, inor)的方法,可以用其它的方法
处理string pre的首位,即为二叉树的树根
而再接着分治
处理string inor即可

遵守OJ纪律请勿复制代码!!!!!!!!!!

难度不大直接上代码

#include <bits/stdc++.h>
using namespace std;
string pre, inor;

void work(string pre, string inor) {
	if (pre.empty())
		return;
	char root = ____;
	int k = inor.find(____);
	pre.erase(pre.begin());
	string leftpre = pre.substr(____, ____);
	string rightpre = pre.substr(____);
	string leftinor = inor.substr(____, ____);
	string rightinor = inor.substr(____, ____);
	work(leftpre, leftinor);
	work(rightpre, rightinor);
	printf("%c", root);
}

int main() {
	cin >> inor >> pre;
	work(____, ____);
	return 0;
}

剩余部分自己理解并填写,不要复制!!!不要复制!!!不要复制!!!


评论:

干的漂亮!!好题解!!大家都应该这么发(手动大拇指)


__0__  •  6个月前