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 miaozishao at 2013-04-02 18:58:28 on Problem 2406
//KMP next 自匹配
#include <iostream>
using namespace std;
#define n 1000010

int Inext[n];
char Istr[n];
void getnext(char str[n],int next[n])
{
	int i=0;
	int l=strlen(str);
	int j=-1;
	next[0]=-1;
	while(i<l)
	{
	if(j==-1 || str[j]==str[i])
	{
		++i;
		++j;
		next[i]=j;
	}
	else
		j=next[j];
	}
}

int main()
{
	while(1)
	{
		scanf("%s",Istr);
		if(!strcmp(Istr,".")) break;
		getnext(Istr,Inext);
		int len=strlen(Istr);
		
		if(len%(len-Inext[len])==0)
			printf("%d\n",len/(len-Inext[len]));
		else
			printf("%d\n",1);
	}
	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