Untitled
raw download clone
TEXT
views 19
,
size 684 b
#include <stdio.h>
#include <string.h>
char S[1001],p[1001];
int check(int idex,int plen,int slen)
{
    for(int j=0;j<plen;j++)
    {
        if(S[idex+j]!=p[j])
            return 0;
    }
    return 1;
}
int main()
{
    int head[1001],q;
    head[0]=0;
    scanf("%s",S);
    scanf("%s",p);
    int slen=strlen(S);
    int plen=strlen(p);
    for(int i=0;i<slen-(plen-1);i++)
    {
        head[i+1]=head[i]+check(i,plen,slen);
    }
    scanf("%d",&q);
    while(q--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        int h=r-plen+1,b=l-1;
        int ans=(h<=b)?0:(head[h]-head[b]);
        printf("%d\n",ans);
    }
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.