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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值