Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

poj 2752 Seek the Name, Seek the Fame

$
0
0
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=1e6+9;
int next[maxn],ans[maxn];
char a[maxn];
int main()
{
    while(scanf("%s",a+1)!=EOF)
    {
        next[1]=0;
        int n=strlen(&a[1]);
        for(int i=2;i<=n;i++)
        {
            int t=i-1;
            while(t&&a[i]!=a[next[t]+1])
            t=next[t];
            next[i]=next[t]+(a[i]==a[next[t]+1]);
        }
        int lon=1;
        ans[1]=n;
        int t=n;
        while(next[t]!=0)
        {
            ans[++lon]=next[t];
            t=next[t];
        }
        printf("%d",ans[lon]);
        for(int i=lon-1;i>=1;i--)
        printf(" %d",ans[i]);
        printf("\n");
        memset(a,0,sizeof(a));
    }
    return 0;
}


作者:yrleep 发表于2013-6-6 1:40:12 原文链接
阅读:20 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>