AcWing 4960. 子串简写
原题链接
中等
作者:
何德何能
,
2024-04-12 20:44:29
,
所有人可见
,
阅读 1
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 500100;
typedef long long LL;
int n;
char str[N];
char st,ed;
vector<int> a, b;
int main()
{
scanf("%d", &n);
scanf("%s", str);
getchar();
scanf("%c %c", &st, &ed);
int len = strlen(str);
int start,end;
for (int i = 0; i < len; i ++ ){
if(str[i] == st){
a.push_back(i);
}
if(str[i] == ed){
b.push_back(i);
}
}
LL res = 0;
int j = 0;
for (int i = 0; i < a.size(); i ++ ){
ed = i;
for(; j < b.size(); ++ j){
if(b[j] - a[i] + 1 >= n){
res += (b.size() - j);
break;
}
}
}
printf("%lld\n",res);
return 0;
}