站外题,求大佬求助,急!
  • 板块学术版
  • 楼主Jasonshan10
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/2/4 20:36
  • 上次更新2023/10/24 01:41:48
查看原帖
站外题,求大佬求助,急!
782125
Jasonshan10楼主2023/2/4 20:36

已知前序遍历和中序遍历,求后序遍历 substr貌似有问题 找不出老来

#include <bits/stdc++.h>
using namespace std;
void f(string a,string b){
	int len=a.size();
	if (len==0){
		return;
	}
	int pos=a.find(b[0]);
	cout<<b[0];
	string x=a.substr(0,pos);
	string y=b.substr(1,pos);
	f(x,y);
	x=a.substr(pos+1,len-pos-1);
	y=b.substr(pos+1,len-pos-1);
	f(x,y);
}
int main(){
	string a,b;
	while (cin>>a>>b){
		f(a,b);
		cout<<endl;
	}
	return 0;
}
2023/2/4 20:36
加载中...