KMP真是个神奇的东西
#include <bits/stdc++.h>
using namespace std;
char mo[10005],str[1000005];
int nextpos[10005];
int t;
int main()
{
//freopen("1.txt", "r", stdin);
scanf("%d",&t);
while(t--){
scanf("%s",mo);
scanf("%s",str);
memset(nextpos,-1,sizeof(nextpos));
int i=0,j=-1,len=strlen(mo);
while(i<len){
if(j==-1||mo[i]==mo[j])
nextpos[++i]=++j;
else j=nextpos[j];
}
int ans=0,len1=strlen(str);
i=j=0;
while(i<len1){
if(j==-1||str[i]==mo[j]){
i++;j++;
}
else j=nextpos[j];
if(j==len)ans++;
}
printf("%d\n",ans);
}
return 0;
}