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

百度的代码,不知道怎么就ac了

Posted by Sunbeam at 2010-11-20 15:04:07 on Problem 2406
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 char str [1000010];
int next[1000010];
 
int getnext()
{
 int i= 0, j= -1; next[0]= -1;
 
while( str[i] )
 {
 if( j== -1 || str[i]== str[j] )
 {
 ++i,++j;
 next[i]= j;
 }
 else j= next[j];
 }
 
int len= strlen(str);
 i= len- j;
 
if( len% i== 0 ) return len/ i;
 else return 1;
}
 int main()
{
 while( gets( str), str[0]!= '.' )
 printf("%d\n", getnext() );
 
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