40求助!!
查看原帖
40求助!!
1152154
Chinami_Nagisa楼主2024/7/30 20:27

我寻思着测试点二也没错啊怎么就WA了

#include <iostream>
using namespace std;
#include <string>
string s1,s2;
string s;
void build(string m,string n,int len,int k)      
{
	s[k]=n[len-1];
	if(len>1)
	{
		int b=m.find(s[k]);
		if(b>0)
		{
			string t1=m.substr(0,b);
			string u1=n.substr(0,b);
			build(t1,u1,b,2*k);	
		}
		if(len-b-1>0)
		{
			string t2=m.substr(b+1,len-b-1);
			string u2=n.substr(b,len-b-1);	
			build(t2,u2,len-b-1,2*k+1);
		}
	}
	else return;
}
void dfs(int k)
{
	cout<<s[k];
	if(s[2*k]!=0) dfs(2*k);
	else return;
	if(s[2*k+1]!=0) dfs(2*k+1);
	else return;
}
int main(){
	cin>>s1>>s2;
	int l=s1.size();
	build(s1,s2,l,1);
	dfs(1);
}
2024/7/30 20:27
加载中...