题目描述
请从字符串中找出至少重复一次的子字符串的最大长度
输入描述:
字符串,长度不超过1000
输出描述:
重复子串的长度,不存在输出0
示例1
输入
复制
ababcdabcefsgg
输出
复制
3
说明
abc为重复的最大子串,长度为3
#include<iostream>
#include<string>
using namespace std;
int main(){
string Input;
cin >> Input;
int MAX = 0;
for(int i = 0;i < Input.size();i ++){
for(int j = i + 1;j < Input.size();j ++){
int Length = 0;
int StartIndex = i;
int EndIndex = j;
while(Input[StartIndex] == Input[EndIndex]){
Length ++;
StartIndex++;
EndIndex++;
}
MAX = max(MAX,Length);
}
}
printf("%d\n",MAX);
return 0;
}