返回题解分享
讨论 / 题解分享/ 帖子详情

子串简写(编程题) - 题解

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

int k;
string s;
char c1, c2;

void solve()
{
	cin >> k;
	cin >> s >> c1 >> c2;

	int cnt = 0, res = 0;

	/*
		样例解释就是思想所在
	*/
	for (int l = 0, r = k - 1; r <= s.length(); l++, r++)
	{
		if (s[l] == c1) cnt++;
		if (s[r] == c2) res += cnt;
	}

	cout << res << endl;
}

signed main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	solve();

	return 0;
}
0 回复 0 转发 0 喜欢 1 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!