#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
char str[1000010];
char s[1000010];
int nextt[1000010];
int len2;
void get_next()
{
nextt[0]=-1;
int i=0,j=-1;
while(i<len2)
{
if(j==-1|s[i]==s[j])
{
i++,j++;
nextt[i]=j;
}
else
j=nextt[j];
}
}
int main()
{
int n,a,b,l,r;
scanf("%d%d%d%d%d",&n,&a,&b,&l,&r);
scanf("%s",s);
len2=strlen(s);
int w,cnt=0;
for(int i=1;i<=n;i++)
{
if(i==1)
{
w=b;
if(w>=l&&w<=r&&w%2==0)str[cnt++]='A';
else if(w>=l&&w<=r&&w%2==1)str[cnt++]='T';
else if((w<l||w>r)&&w%2==0)str[cnt++]='G';
else if((w<l||w>r)&&w%2==1)str[cnt++]='C';
}
else
{
w=(w+a)%n;
if(w>=l&&w<=r&&w%2==0) str[cnt++]='A';
else if(w>=l&&w<=r&&w%2==1)str[cnt++]='T';
else if((w<l||w>r)&&w%2==0)str[cnt++]='G';
else if((w<l||w>r)&&w%2==1)str[cnt++]='C';
}
}
str[cnt]='\0';
get_next();
int j=0,sum=0,i=0;
//printf("%s\n",str);
while(i<n)
{
if(str[i]==s[j])
{
j++,i++;
if(j==len2)
{
sum++;
}
}
else if(nextt[j]==-1)//把这种情况分出来,让j重新匹配
i++;
else
{
j=nextt[j];
}
}
printf("%d\n",sum);
return 0;
}
KMP匹配原串中有多少子串
最新推荐文章于 2023-01-02 11:27:34 发布