A - You‘re Given a String

Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64u

[Submit [GoBack  [Status]

Description

You're given a string of lower-case Latin letters. Your task isto find the length of its longest substring that can be met in thestring at least twice. These occurrences can overlap (see sampletest 2).

Input

The first input line contains the string. It's guaranteed, thatthe string is non-empty, consists of lower-case Latin letters, andits length doesn't exceed 100.

Output

Output one number — length of the longest substring that can bemet in the string at least twice.

Sample Input

Input
abcd

Output
0
Input
ababa

Output
3
Input
zzz

Output
2
 
       
题意:
在所给字符串中找出最少出现两次的最长子串的长度
#include<iostream>
using namespace std;
int main()
{
        int i,j;
        int l,t,maxl;
    char str[105];
        while(cin>>str)
        {    
                maxl=0;
                l=strlen(str);
             for(i=0;i<l;i++)// 从str[0]向后开始枚举
        {
                for(j=i+1;j<l;j++)//一个个向后比较
                {
                        t=0;
                 while(str[i+t]==str[j+t]) t++;//当找到第一个时,同时后移
                      maxl=t>maxl?t:maxl; //保存将当前至少2次重复的最长字串
                                        //  长度          
                }
        }
                 cout<<maxl<<endl;
        }
        return 0;
        
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值