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 OZY123 at 2016-03-29 13:43:00 on Problem 2406
#include<cstdio>
#include<cstring>
char s[1000005],k[1000005];
int len,len1;
int f[1000005];
int num;
void qs ()
{
	f[0]=-1;
	int i=1,j=-1;
	for (;i<len;i++)
	{
		while (j!=-1&&s[i]!=s[j+1]) j=f[j];
		if (s[i]==s[j+1]) j++;
		f[i]=j;
	}
}
int main()
{
	while (true)
	{
		scanf("%s",s);
		if (strcmp(s,".")==0) break;
		len=strlen(s);
		qs();
		//for (int u=0;u<len;u++) printf("%d ",f[u]);
		int t=len-f[len-1]-1;
		//printf("%d\n",t);
		if (t==0) printf("1");
		else if (len%t==0) printf("%d",len/t);
		else printf("1");
		printf("\n");
	}
	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