题目
由于题目中要求该字符子串出现两次所以直接从头开始进行匹配,第一个for代表该字符子串第一次出现,第二个for代表该字符子串第二次出现。通过max记录最大长度。
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main( )
{
string s;
cin>>s;
int len=s.size();
int maxx=0;
for(int i=0;i<len;i++)
{
for(int j=i+1;j<len;j++)
{
int m=0;
while(s[i+m]==s[j+m])
m++;
maxx=max(m,maxx);
}
}
cout<<maxx<<endl;
return 0;
}