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

o(n)还TLE?!

Posted by waterine at 2005-04-27 00:26:52 on Problem 2406
#include <stdio.h>
#include <string.h>
void main()
{
char str[1000];
int next[1000];
int len;	int i,j;
	while(1)
	{
		scanf("%s",str);
		if(str[0]=='.') return;
		len=strlen(str);
		i=0, j=-1;
		next[0] = -1;
		while(i<len)
		{ 
			if(j==-1||(j>=0&&str[i]==str[j]))
			{
				i++;
				j++;
				next[i]=j;
			}
		else
			j=next[j];
		}
  		i-=j;
        if(len%i==0)i=len/i; else i=1;
		printf("%d\n",i);
	}
}

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