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

想知道为什么错了看了就知道了

Posted by chenxuan123456789 at 2012-09-08 22:56:45 on Problem 2406
#include <stdio.h>
#include <string.h>
int next[1000010],len;
char str[1000010];
void getnext()
{
	int j,k;
	j=0;
	k=-1;
	memset(next,0,sizeof(next));
	next[0]=-1;
	while(j<len)
	{
		if(k==-1||str[j]==str[k])
		{
			j++;
			k++;
			next[j]=k;
		}
		else
			k=next[k];
	}
}
int main()
{
	while(scanf("%s",str)!=EOF)
	{
		if(strcmp(str,".")==0)
		break;
		len=strlen(str);
		getnext();
		 if (len%(len-1-next[len-1]))
			 printf("1\n");
        else 
			printf("%d\n", len/(len-1-next[len-1]));

	}
	return 1;
}



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