gpt4 book ai didi

c++ - 递归如何在此代码中工作?

转载 作者:行者123 更新时间:2023-11-28 05:39:27 26 4
gpt4 key购买 nike

<分区>

// interleaving of two string

#include<bits/stdc++.h>

using namespace std;

bool isinterleav(string & a, string & b, string & c, int i, int j, int k) {

if(i == -1 && k == -1 && j == -1) return true;

bool x = false, y = false ;
if(a[i] == c[k]) x = isinterleav(a,b,c,i-1,j,k-1);
//cout << x <<" " << y << " " << i << " " << j << " " << k << endl;
if(b[j] == c[k]) y = isinterleav(a,b,c,i,j-1,k-1);
return x || y;
}

int main() {

string a = "AFGHA", b = "ABCDA", c = "AFGHAABCDA";
int i, j, k;
//cin >> a >> b >> c;

i = a.length()-1;
j = b.length()-1;
k = c.length()-1;

if(isinterleav(a,b,c,i,j,k))
cout << "Yes" << endl;
else cout << "No" << endl;

return 0;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com