您的位置:首页 > 其它

Solve equation

2016-03-27 14:54 260 查看
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


</pre><pre name="code" class="cpp">#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<cstdio>
#include<string>
using namespace std;
map<string,int>num;
int main()
{
string s,name;
int i,j,k,n;
cin>>s;
n=s.size();
for(k=1;k<=n;k++) {
for(i=0;i+k<=n;i++) {
name="";
for(j=i;j<i+k;j++) {
name=name+s[j];
}
num[name]++;
if(num[name]>1) break;
}
if(i+k>n) break;
}
cout<<k-1<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: