码迷,mamicode.com
首页 > 其他好文 > 详细

You're Given a String...

时间:2017-12-03 19:55:20      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:lin   ons   sam   tin   spec   cee   ati   div   case   

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.

Example
Input
abcd
Output
0
Input
ababa
Output
3
Input
zzz
Output
2
找重复出现至少一次的最大子串长度
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#define Max 1001
using namespace std;
char s[101];


int main()
{
    cin>>s;
    int d = 0;
    for(int i = 0;i < strlen(s) - 1;i ++)
    {
        for(int j = i + 1;j < strlen(s);j ++)
        {
            int cnt = 0;
            while(j + cnt <strlen(s)&&s[i + cnt] == s[j + cnt])cnt ++;
            if(d < cnt)d = cnt;
        }
    }
    cout<<d<<endl;
}

 

You're Given a String...

标签:lin   ons   sam   tin   spec   cee   ati   div   case   

原文地址:http://www.cnblogs.com/8023spz/p/7966827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!