| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
第一次贴代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator