A. You're Given a String...

A. You're Given a String...
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
Input
abcd
Output
0
Input
ababa
Output
3
Input
zzz
Output
2
#include<iostream>
#include<stdio.h>
#include<set>
using namespace std;
int main()
{
    string str;
    cin>>str;
    set<string> Set;
    for(int i=str.size();i>=1;i--)
    {
        Set.clear();
        for(int j=0;j+i<=str.size();j++)
        Set.insert(str.substr(j,i));
        if(Set.size()!=str.size()-i+1)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"0"<<endl;
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章