Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
1A#include<cstdio> #include<cstring> #include<algorithm> #define N 1000000 using namespace std; int pre[N]; char s[N]; void print(int i) { if(i)print(pre[i]),printf("%d ",i); return ; } int main() { // freopen("test.in","r",stdin); int n,i,len; while(scanf("%s",s+1)!=EOF) { n=1; memset(pre,0,sizeof(pre)); while(s[n]!='\0')n++; for(n--,len=0,i=2;i<=n;i++) { while(len&&s[i]!=s[len+1])len=pre[len]; if(s[i]==s[len+1])len++; pre[i]=len; } print(pre[n]); printf("%d\n",n); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator