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;
}
}
}
kxc:
Console.WriteLine(z);
Console.ReadKey();
随手写的有点不规范,不过效果实现了,希望能给你帮助 |