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 920235063 at 2015-12-22 12:48:22 on Problem 3461
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n=0,len=0,len1=0,ans=0;
int next[10001]={0};
char s[10001]={'\0'},s1[1000001]={'\0'};
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		ans=0;
		memset(next,0,sizeof(next));
		next[0]=-1;
		scanf("%s",&s);
		scanf("%s",&s1);
		len=strlen(s);
		len1=strlen(s1);
		for(int i=1,j=0;i<len;++i)
		{
			for(j=next[i-1];j!=-1&&s[j+1]!=s[i];j=next[j]);
			if(s[j+1]==s[i])
				++j;
			next[i]=j;
		}
		for(int i=0,j=-1;i<len1;++i)
		{
			for(;j!=-1&&s[j+1]!=s1[i];j=next[j]);
			if(s[j+1]==s1[i])
				++j;
			if(j==len-1)
				++ans;
		}
		printf("%d\n",ans);
	}
}

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