给定一个字符串,求出其最长的重复子串。
string FindStr(conststring &str)
{
string temp, MaxStr;
intMaxLen = 0;
for(inti = 0; i < str.length(); ++i)
{
for(intj = str.length() - 1; j>i; --j)
{
temp = str.substr(i, j);
intfront = str.find(temp);
intbehind = str.rfind(temp);
inttemplen = temp.length();
if(front != behind&&templen > MaxLen)
{
MaxStr = temp;
MaxLen = templen;
}
}
}
returnMaxStr;
}