You're Given a String...

Posted 给杰瑞一块奶酪~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了You're Given a String...相关的知识,希望对你有一定的参考价值。

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...的主要内容,如果未能解决你的问题,请参考以下文章

[CF1202B] You Are Given a Decimal String(最短路)

codeforces1202B You Are Given a Decimal String... 记忆化搜索或Floyd最短路算法

(模拟)关于进制的瞎搞---You Are Given a Decimal String...(Educational Codeforces Round 70 (Rated for Div. 2))

[2016-05-25]OMG美语笔记-Have you ever felt like you had fever and you're burning up like really,real

翻译lenka的歌曲《live like you re dying》

URAL 1997 Those are not the droids you're looking for