题解 | #二叉树遍历#

二叉树遍历

https://www.nowcoder.com/practice/6e732a9632bc4d12b442469aed7fe9ce

#include<iostream>
#include<stack>
using namespace std;
void out(string s1,string s2,int low1,int high1,int low2,int high2,stack<char> &s){
	if(low1 > high1 || low2 > high2)return;
	char head = s1.at(low1);
	int p = low2;
	while(s2.at(p)!=head)p++;
	s.push(head);
	int length1 = p-low2;//1 2 3 4(p) 5 6 7
						 //4(p) 2 3 1 5 7 6
	int length2 = high2-p;
	out(s1,s2,low1+1,low1+length1,p-length1,p-1,s);
	out(s1,s2,low1+length1+1,high1,p+1,high2,s);
	cout<<head;
	s.pop();	
}
int main(){
	string s1 = "";
	string s2 = "";
	while(cin>>s1){
		if(cin.eof())break;
		cin>>s2;
		stack <char>s;

	out(s1,s2,0,s1.length()-1,0,s2.length()-1,s);
	cout<<endl;
	
	}
	return 0;
}

全部评论

相关推荐

感觉他们一点都不了解现在这个社会就业有多难,已经在牛客刷到好多篇&nbsp;延毕的帖子了,延毕就会导致已经找好的工作就没了,还得重新再找,学校和老师们是怎么想的呢????看到学生丢失工作会开心吗&nbsp;就业数据都在造假,真实的就业困难不去解决&nbsp;一个个真是好样的
从明天开始狠狠卷JV...:学生看到的是导师不放实习导致offer黄了。 导师看到的是招进来的学生吃自己补助和自己的招生名额,却没给自己升迁带来任何帮助,还要跑路。 根本利益的不一致,最主要留校的导师大概率是职场上招聘失败的,被迫留校的,什么牛鬼蛇神都会有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务