Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

无限WA啊,我真心找不出哪错了,求大神指点啊

Posted by wpsxiaowang1 at 2012-03-31 22:27:10 on Problem 2752
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator