为什么ipos只是在dfs()里的局部变量,不能是全局变量
查看原帖
为什么ipos只是在dfs()里的局部变量,不能是全局变量
521875
AORANGEE楼主2022/3/30 22:52
#include<cstdio>
#include<iostream>
#include<queue>
#include<string>
using namespace std;
string A, B;
int nlen;
int sfind(string s,char c)
{
	for (int i = 0; i < nlen; i++)
	{
		if (c == s[i]) return i;
	}
}
void dfs(int l1,int r1, int l2, int r2)
{
	int ipos = sfind(A,B[r2]);
	cout << B[r2];
	if (ipos > l1&&ipos>=0) dfs(l1, ipos - 1, l2, r2 - r1 + ipos - 1);
	if (ipos < r1) dfs(ipos + 1, r1, l2 + ipos - l1, r2 - 1);
}
int main()
{
	cin >> A;
	cin>>B;
	nlen = A.length();
	dfs(0, nlen - 1, 0, nlen-1);
	return 0;
}
2022/3/30 22:52
加载中...