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

1A

Posted by 18357 at 2014-08-12 20:00:37 on Problem 2752
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1000000
using namespace std;
int pre[N];
char s[N];
void print(int i)
{
	if(i)print(pre[i]),printf("%d ",i);
	return ;
}
int main()
{
//	freopen("test.in","r",stdin);
	int n,i,len;
	while(scanf("%s",s+1)!=EOF)
	{
		n=1;
		memset(pre,0,sizeof(pre));
		while(s[n]!='\0')n++;
		for(n--,len=0,i=2;i<=n;i++)
		{
			while(len&&s[i]!=s[len+1])len=pre[len];
			if(s[i]==s[len+1])len++;
			pre[i]=len;
		}
		print(pre[n]);
		printf("%d\n",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