概念:
// 字符串 abcdef
// 字符串的子串:abcde, abc, ab, a, bcdef, bcde ......
// 字符串的子序列:acd, adf, acdf, bef, bf ......
代码:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
// 字符串 abcdef
// 字符串的子串:abcde, abc, ab, a, bcdef, bcde ......
// 字符串的子序列:acd, adf, acdf, bef, bf ......
int F(string _mainstr, string _substr)
{
if(_mainstr.length() == 0 || _substr.length() == 0)
return 0;
if(_mainstr.at(0) == _substr.at(0))
return F(_mainstr.substr(1), _substr.substr(1)) + 1;
else
return max(F(_mainstr.substr(1), _substr), F(_mainstr, _substr.substr(1)));
}
int main()
{
string mainstr = "abcdef";
string substr = "xbdcnefe";
//cout << mainstr.substr(1, mainstr.length());
cout << F(mainstr, substr);
return 0;
}