zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    08-12 NOIP模拟测试18
    08-09 NOIP模拟测试15
    08-11 NOIP模拟测试17
    08-10 NOIP模拟测试16
    08-07 NOIP模拟测试14
    08-03 NOIP模拟测试12
    [SDOI2011]拦截导弹
    08-01 NOIP模拟测试11
    零散知识点
    07-29 NOIP模拟测试10
  • 原文地址:https://www.cnblogs.com/8023spz/p/7966827.html
Copyright © 2011-2022 走看看