AC

♻️lzhh_lzhh32  •  3个月前


#include<bits/stdc++.h> 
using namespace std;
string s1,s2;		//s1前序遍历,s2中序遍历 
int cnt=1,ans;
void maketree(int left1,int right1,int left2,int right2){
	char root=s1[left1];
	int find;
	for(find=left2;find<=right2;find++){
		if(s2[find]==root){
			maketree(left1+1, left1+find-left2, left2, find-1);		//左子树 
			maketree(right1-(right2-find)+1, right1, find+1, right2);		//右子树
			if(cnt%2==1) ans+=root-'0';
			cnt++;
		}
	}
} 
int main(){
	cin>>s1>>s2;
	maketree(0,s1.size()-1,0,s2.size()-1);
	cout<<ans<<endl;
	return 0;
}


评论:

请先登录,才能进行评论