Untitled
raw download clone
C
views 13
,
size 544 b
#include<stdio.h>
#include<string.h>
#define MAX_N 1003
char s[MAX_N], p[MAX_N];
int pre[MAX_N];

int main(void)
{
    scanf("%s",s+1);
    scanf("%s",p+1);
    int q;
    int ls = strlen(s+1), lp = strlen(p+1);
    for(int i = 1;i <= ls-lp ;i++)
    {
         pre[i] = pre[i-1];
         if(strncmp(s+i, p+1, lp)==0) pre[i]++;
    }
    scanf("%d",&q);
    while(q--)
    {
        int l, r;
        scanf("%d%d",&l, &r);
        int ans = pre[r-lp+1] - pre[l-1];
        printf("%d\n",(ans > 0 ? ans : 0));
    }

}
close fullscreen
Login or Register to edit or fork this paste. It's free.