题目:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/78b27792320a367db0059070c3485929.png)
分析:又出现了小错误了,粗心不断。考试就完蛋了。
代码:
#include<bits/stdc++.h>
using namespace std;
string s1;
string s2;
void f(int x1,int x2,int y1,int y2)
{
if(x1==x2)
{
cout<<s1[x1];
return;
}
if(x1+1==x2)
{
cout<<s2[y2]<<s2[y1];
return;
}
if(s1[x1]==s2[y1])
{
f(x1+1,x2,y1+1,y2);
cout<<s2[y1];
return;
}
if(s1[x2]==s2[y1])
{
f(x1,x2-1,y1+1,y2);
cout<<s2[y1];
return;
}
int c;
for(int i=x1;i<=x2;i++)
{
if(s1[i]==s2[y1])
{
c=i;break;
}
}
f(x1,c-1,y1+1,y1+c-1-x1+1);
f(c+1,x2,y1+c-1-x1+1+1,y2);
cout<<s1[c];
}
int main()
{
cin>>s1>>s2;
f(0,s1.length()-1,0,s1.length()-1);
}