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 |
无限WA啊,我真心找不出哪错了,求大神指点啊#include<stdio.h> #include<string.h> #define N 400002 int next[N],Fame[N]; char str[N]; void next1(int len) { int i,j=0; memset(next,0,sizeof(next)); next[1]=0; for(i=2;i<len;i++) { while(j>0&&str[j+1]!=str[i]) { j=next[j]; } if(str[i]==str[j+1]) { j++; } next[i]=j; } } void function(int len) { int i,j; Fame[0]=len; j=1; i=len-1; i=next[i]; while(i!=0) { Fame[j++]=(i+1); i=next[i]; } if(str[0]==str[len-1]&&len!=1) { printf("1 "); } for(i=j-1;i>=0;i--) { if(i!=0) printf("%d ",Fame[i]); else printf("%d\n",Fame[i]); } } int main() { int len; while(scanf("%s",str)!=EOF) { len=strlen(str); next1(len); function(len); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator