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

大家来看看我的为什么wa

Posted by simple85 at 2008-07-05 22:22:50 on Problem 1961
#define MAX_LENGTH 1000001
#include<stdio.h>
char s[MAX_LENGTH];
int next[MAX_LENGTH];
int length,count,num=0;
void get_next(char s[],int next[])
{
	int i=1,j=0;
	next[1]=0;
	while(i<=length)
	{
		if(j==0||s[i]==s[j])
		{
			i++;
			j++;
			next[i]=j;
		}
		else
			j=next[j];
	}
}

void func()
{
	printf("Test case #%d\n",++num);
	for(int k=2;k<=length;k++)
	{
		if(k%((k+1)-next[k+1])==0)
		{
			count=k/((k+1)-next[k+1]);
			if(count!=1)
				printf("%d %d\n",k,count);
		}
	}
	printf("\n");
}

int main()
{
	//freopen("in.txt","r",stdin);
	while(1)
	{
		scanf("%d",&length);
		if(!length)
			break;
		scanf("%s",s+1);
		get_next(s,next);
		func();
	}
	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