AcWing 4960. 子串简写
原题链接
中等
作者:
黑人小白
,
2025-04-04 21:51:10
· 浙江
,
所有人可见
,
阅读 1
using namespace std;
cout <<
for (int i = 1; i <= n; i++) \
{ \
for (int j = 1; j <= m; j++) \
{ \
cout << arr[i][j] << " "; \
} \
cout << endl; \
} \
cout << endl
typedef long long ll;
const int N = 5e5 + 5;
const int INF = 0x3f3f3f;
int cnt[N];
int lastc1 = -1;
char c1, c2;
string s;
int k;
ll res = 0;
void solve()
{
cin >> k;
cin >> s;
cin >> c1 >> c2;
int l = s.size();
for (int i = 0; i < l; i++)
{
char c = s[i];
cnt[i]+=cnt[i - 1];
if (c == c1)
{
cnt[i]++;
}
if (c == c2)
{
int pre = i-k+1;
if(pre>=0){
res+=cnt[pre];
}
}
}
cout << res << endl;
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
solve();
return 0;
}