Brief description:
斩头去尾而不伤及加密内容的方案数。
Analysis:
… . 扫一遍吧。
string T, P;
int n, m; LL res;
int main(){
//freopen("in.txt", "r", stdin);
cin >> T >> P, n = SZ(T), m = SZ(P);
int _i = -1;
for (int i=0;i<n;++i){
if (T[i] == P[0]){
int i_ = i + 1, j = 1;
while (i_ < n && j < m){
if (T[i_] == P[j]) ++j;
++i_;
}
if (j < m) break;
res += LL (i - _i) * (n - i_ + 1);
_i = i;
}
}
cout << res << endl;
}
发表回复