#include <iostream>
#include <vector>
using namespace std;
static vector<int> pos_in_str;
void find_sub_link(const char* p1, const char* p2, int i, int j)
{
if( !p1[i] || !p2[j] )
return;
if( p2[j]==p1[i] && !p2[j+1] ) {
for(vector<int>::iterator it = pos_in_str.begin(); it != pos_in_str.end(); it++) {
cout << *it << " ";
}
cout << i+1 << endl;
}
else if (p2[j] == p1[i]) {
pos_in_str.push_back(i + 1);
find_sub_link(p1, p2, i + 1, j + 1);
pos_in_str.pop_back();
}
find_sub_link(p1, p2, i + 1, j);
}
int main(int argc, char **argv)
{
char str1[10] = "abdbcca";
char str2[10] = "abc";
find_sub_link(str1, str2, 0, 0);
return 0;
}
程序员面试宝典_8.2_典型递归问题_面试例题1
最新推荐文章于 2019-10-09 07:28:00 发布