Description You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). Input The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. Output Output one number — length of the longest substring that can be met in the string at least twice. Sample Input
Input
abcd
Output
0
Input
ababa
Output
3
Input
zzz
Output
2 这个题目的意思是说找出其子串中最大循环的个数,我很惭愧,在kmmm的这个例子里,应该是2,可我一开始认为是0.是子串,可以包含没有的,所以不可以用kmp,因为kmp数组求出的是前面的最大匹配数目,这个时候有人可能会问假如遍历next[],数组求出最大的不就行了吗,其实不行的,因为在aaa,中,next[]最大是3,而其实是2的,所以暴力比较是个不错的法子。
|
codeforences 29A
最新推荐文章于 2024-09-26 19:35:50 发布