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

why wa??

Posted by hdjtdxacm at 2009-04-01 20:29:55 on Problem 2406
#include<stdio.h>
#include<string.h>
char s[1000005];
int next[1000005];
int main()
{
	int i,j,k,len;
	while(1)
	{
		scanf("%s",s+1);
		if(strcmp(s+1,".") == 0)
			break;
		len = strlen(s+1);
		if(len == 1)
		{
			printf("1\n");
			continue;
		}
		if(len == 2)
		{
			if(s[1] == s[2])
				printf("2\n");
			else
				printf("1\n");
			continue;
		}
		next[1] = 0;
		i = 1;j = 0;
		while(i < len&&j < len)
		{
			if(j == 0||s[i] == s[j])
			{
				i++;j++;
				next[i] = j;
			}
			else
				j = next[j];
		}
	///	printf("len = %d,j = %d\n",len,j);
		k = len - j;
		if(!(len%k))
	    	printf("%d\n",len/k);
		else
			printf("1\n");
	}
	return 0;
}
/*
Sample Input
abcd
aaaa
ababab
.
Sample Output

1
4
3
*/

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