zoukankan      html  css  js  c++  java
  • Simpsons’ Hidden Talents

    题目大意:给你两个字符串,找出一个最大的子串,这个子串要是前面串的前缀并且是后面串的后缀...........
     
    分析:next的简单运用吧,可以把两个串进行合并,中间加一个不能被匹配的字符,然后求出来next就行了.......确实很水
    代码如下:
    =========================================================================================================
    #include<stdio.h>
    #include<string.h>
    
    const int MAXN = 1e5+7;
    const int oo = 1e9+7;
    
    char a[MAXN], b[MAXN];
    int next[MAXN];
    
    void GetNext(char s[], int N)
    {
        int i=0, j=-1;
        next[0] = -1;
    
        while(i < N)
        {
            if(j==-1 || s[i]==s[j])
                next[++i] = ++j;
            else
                j = next[j];
        }
    }
    
    int main()
    {
        while(scanf("%s%s", a, b) != EOF)
        {
            int N = strlen(a);
    
            a[N] = '*', a[N+1] = 0;
            strcat(a, b);
            N = strlen(a);
    
            GetNext(a, N);
    
            if(next[N] == 0)
                printf("0
    ");
            else
            {
                a[next[N]] = 0;
                printf("%s %d
    ", a, next[N]);
            }
        }
    
        return 0;
    }
  • 相关阅读:
    Linux_day01_primaryCommand
    Variational auto-encoder VS auto-encoder
    python yield generator 详解
    Paper Writing
    DTU_AI lecture 09
    DTU_AI lecture 08
    Attention mechanism
    Energy Journals
    TF + pytorch学习
    expRNN
  • 原文地址:https://www.cnblogs.com/liuxin13/p/4731847.html
Copyright © 2011-2022 走看看