有俩字符串“ahfjksdfhsa” “wrdssdfhijtg” 它们两个的最大公共子字符串是“sdfh”
试着写了写循环,最后还是没写出来,绕晕在里边了
求算法作者: 蔡尚猛 时间: 2012-7-28 21:58
int s;
string a = "ahfjksdfhsa";
string b = "wrdssdfhijtg";
string max = "";
string min = "";
string z="";
if (a.Length > b.Length)
{
s = b.Length;
max = a;
min = b;
}
else
{
s = a.Length;
max = b;
min = a;
}
for (int i = s; i >= 0;i-- )
{
for(int k=0;k<min.Length-i;k++)
{
if (max.IndexOf(min.Substring(k, i)) >= 0)
{
z=min.Substring(k,i);
goto kxc;
}
}