CodeForces 23A You're Given a String...

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



Code :

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define eps 1e-7
#define LL long long
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;

const int inf=0x3f3f3f3f;
const int maxn=105;
char str[maxn],tmp[maxn];

int main()
{
    scanf("%s",str);
    int tot=0;
    int ans;
    char *index=NULL;
    int len=strlen(str);
    bool flag=false;
    for(ans=len-1;ans>=1;ans--){
        for(int i=0;i<=len-ans;i++){
            strncpy(tmp,str+i,ans);
            tmp[ans]='\0';
            index=strstr(str,tmp);
            if(strstr(index+1,tmp)) {
                    flag=true;
                    break;
            }
        }
        if(flag) break;
    }
    printf("%d\n",ans);
    return 0;
}


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