题目链接:
这题直接用KMP算法就能够做出来,只是我还尝试了用扩展的kmp,这题用扩展的KMP效率没那么高。
KMP算法:
#include#include #include using namespace std;int next[50001];char p[50000],s[50000];void getnext(){ int plen=strlen(p),k=0,j=1; next[0]=-1;next[1]=0; while (j
扩展的KMP:
#include#include #include using namespace std;char S[50000],T[50000];int A[50001],B[50001],sl,tl;void getA(){ int j=0; while(1+j 0) { for (int j=0;j