题目链接:
暴力:
#include#include char a[15];char b[1005];int len1,len2;int main(){ int t; scanf("%d",&t); while(t--) { int i,j; int Count=0; scanf("%s%s",a,b); len1=strlen(a); len2=strlen(b); for(i=0;i
STL:
///STL#include#include #include #include using namespace std;int main(){ int t; cin>>t; while(t--) { string p,s; cin>>p>>s; int ans=0; int num=0; ans=s.find(p,0); while(ans!=string::npos) { num++; ans=s.find(p,ans+1); } printf("%d\n",num); } return 0;}
KMP
///KMP#include#include #include #include using namespace std;char p[1005],s[1005];int next[1005];void getnext()///对齐p[j]{ int i=0,j=-1,len=strlen(p); next[0]=-1; while(i