如题:
#include<iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
char str[1002000];
char temp[10200];
int Next[10200],L,l,coun;
void getnext()
{
int i=0,j=-1;
Next[0]=-1;
while(i<l)
{
if(j==-1||temp[j]==temp[i])
Next[++i]=++j;
else
{
j=(temp[j]==temp[Next[j]])?Next[Next[j]]:Next[j];
}
}
}
void KMP(int start)
{
int i=start,j=0;
while(i<=L)
{
while(j>=0&&temp[j]!=str[i])
{
j=Next[j];
}
if(j==l-1)
{
coun++;
i++;
j=Next[j+1];
}
else
{
j++;
i++;
}
}
return ;
}
int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",temp);
scanf("%s",str);
l=strlen(temp);
L=strlen(str);
getnext();
coun=0;
KMP(0);
printf("%d %d %d %d %d %d %d\n",Next[0],Next[1],Next[2],Next[3],Next[4],Next[5],Next[6]);
printf("%d\n",coun);
}
}