zoukankan      html  css  js  c++  java
  • POJ 2752 同一个串的前后串

    题解东北赛回来再补
    
    
    #include<stdio.h>
    #include<string.h>
    
    int next[500000];
    int ans[500000];
    char str[500000];
    
    
    void get_next(int m)
    {
       int j ,k;
       j = 0 ,k = -1;
       next[0] = -1;
       while(j < m)
       {
           if(k == -1 || str[k] == str[j])
           next[++j] = ++k;
           else k = next[k];
       }
    }
    
    int main ()
    {
        while(~scanf("%s" ,str))
        {
            int m = strlen(str);
            get_next(m);
            int an = 0;
            ans[++an] = m;
            while(next[ans[an]])
            {
               int tmp = next[ans[an]];
               ans[++an] = tmp;
            }
            for(int i = an ;i >= 1 ;i --)
            if(i == an) printf("%d" ,ans[i]);
            else printf(" %d" ,ans[i]);
            printf("
    ");
         }
         return 0;
    }

  • 相关阅读:
    cmake
    docker
    rust
    linux
    FPGA
    visual studio
    win+R
    word文档的导出(用freemarker模板导出)(桃)
    iconfont的引入方法
    jquery 日期插件
  • 原文地址:https://www.cnblogs.com/csnd/p/12063058.html
Copyright © 2011-2022 走看看