#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;
const int p=59;
vector<int> hash1,hash2,p1,p2;
string s,t;
int n,m,ans=0;
void init(const string& str,vector<int>& hash,vector<int>& pp)
{
pp[0]=1;
for (int i=1;i<str.size();i++)
{
pp[i]=pp[i-1]*p;
hash[i]=hash[i-1]*p+str[i];
}
return;
}
int hashh(int l,int r,const vector<int>& h,const vector<int>& pp)
{
return h[r]-h[l-1]*pp[r-l+1];
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>s>>t;
n=s.size();
m=t.size();
s='@'+s;
t='@'+t;
p1.resize(n+1,0);
p2.resize(n+1,0);
hash1.resize(n+1,0);
hash2.resize(m+1,0);
init(s,hash1,p1);
init(t,hash2,p2);
for (int l=1;l+m-1<=n;l++)
{
int r=l+m-1;
if (hashh(l,r,hash1,p1)==hash2[m])
{
ans++;
}
}
cout<<ans;
return 0;
}剪贴板
剪贴板 9dv81nwc
剪贴板信息
剪贴板信息
- 收录
- 更新