Test instructions: Count the number of occurrences of one of the substrings
Puzzle: The number of j==m in the KMP algorithm
//Author: 1085422276#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>//#include <bits/stdc++.h>#include <map>#include<stack>typedefLong Longll;using namespacestd;Const intINF =10000000; inline ll read () {ll x=0, f=1; CharCh=GetChar (); while(ch<'0'|| Ch>'9') { if(ch=='-') f=-1; CH=GetChar (); } while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); } returnx*F;} ll EXGCD (ll A,ll b,ll&x,ll &y) {ll temp,p; if(b==0) {x=1; Y=0; returnA; } P=EXGCD (b,a%b,x,y); Temp=x; X=y; Y=temp-(A/b) *y; returnp;}//*******************************intp[1000001];intMain () {intT; scanf ("%d",&T); while(t--) { stringb; CIN>>b>>A; A=" "+A; b=" "+b; intm=b.length (); intn=a.length (); N--, m--; Memset (P,0,sizeof(p)); intj=0; for(intI=2; i<=m;i++) { while(j>0&&b[j+1]!=b[i]) j=P[j]; if(b[j+1]==b[i]) J + +; P[i]=J; } intans=0; J=0; for(intI=1; i<=n;i++) { while(j>0&&b[j+1]!=a[i]) j=P[j]; if(b[j+1]==a[i]) J + +; if(j==m) {ans++; }} cout<<ans<<Endl; } return 0;}Code
POJ 3461 Oulipo KMP