当前位置: 代码迷 >> 综合 >> 【POJ2752】seek the name,seek the fame
  详细解决方案

【POJ2752】seek the name,seek the fame

热度:13   发布时间:2024-01-13 10:03:11.0

题目链接:http://poj.org/problem?id=2752
题解:
一直跳next就好

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[400010]; 
int nxt[400010],stack[400010];void Get_nxt(char *s,int len,int nxt[])
{int j=0;nxt[1]=0;for(int i=2;i<=len;i++){while(j&&s[i]!=s[j+1]) j=nxt[j];j+=(s[i]==s[j+1]);nxt[i]=j;}
}int main()
{while(~scanf("%s",s+1)){int len=strlen(s+1);Get_nxt(s,len,nxt);int p=nxt[len],top=0;while(p){stack[++top]=p;p=nxt[p];}while(top)printf("%d ",stack[top--]);printf("%d\n",len); }return 0;
}