int LCS(const string &str1, const string &str2)
{
int len1 = 0;
int len2 = 0; //记录字符串长度;
int longest_len = 0; //记录子串长度;
len1 = str1.size();
len2 = str2.size();
for (int i = 0; i< len1; i++)
{
for (int j = 0; j< len2; j++)
{
int m = i;
int n = j;
int sub_len = 0;
while (m < len1 && n < len2)
{
if (str1[m] != str2[n])
break;
m++;
n++;
sub_len++;
}
}
if (longest_len < sub_len)
{
longest_len = sub_len;
}
}
return longest_len;
}
阅读(652) | 评论(0) | 转发(0) |