题意:给出一个字符串 然后给出一个前缀和一个后缀 求计算由这个前缀和后缀组成的在这个母串里面的
不同子串的个数
解法:求不同的字符串 这个直接hash就可以了
然后我们暴力就是先求出所有的前缀在母串中出现的位置和所有后缀在母串中出现的位置
然后直接n^2里面 用字符串hash判重就可以了
这题set会T 真的 vector保平安
#include<set>
#include<string>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
vector<int>pos(const string&s,const string&p){
vector<int>ret;
for(string::size_type i=s.find(p);i!=string::npos;i=s.find(p,i+1))
ret.push_back(i);
return ret;
}
int main() {
string str,pre,suffix;
cin>>str>>pre>>suffix;
vector<int>st,ed;
set<ll>ha;
st=pos(str,pre);
ed=pos(str,suffix);
for(int i: st){
ll ans=0;int k=i;
for(int j: ed){
if(i<=j&&i+(int)pre.length()<=j+(int)suffix.length()){
while(k<j+(int)suffix.length()){
ans=ans*29+str[k++];
}
ha.insert(ans);
}
}
}
printf("%d\n",ha.size());
return 0;
}