目录
牛客HJ75 公共子串计算
解析代码
牛客HJ75 公共子串计算
公共子串计算_牛客题霸_牛客网
解析代码
#include <iostream>
using namespace std;
int main()
{
string str1 = "", str2 = "";
cin >> str1 >> str2;
int n1 = str1.size(), n2 = str2.size();
int res = -1;
for (int i = 0; i < n1; ++i)
{
for (int j = 0; j < n2; ++j)
{
int cnt = 0;
int tmpi = i, tmpj = j;
while (tmpi < n1 && tmpj < n2 && str1[tmpi++] == str2[tmpj++])
{
++cnt;
}
res = max(res, cnt);
}
}
cout << res << endl;
return 0;
}