欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

蓝桥杯比赛题目解析:简化子串的暴力与二分方法 - 二部分:暴力解法

最编程 2024-01-26 10:03:47
...

//暴力代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;

void solve()
{
	int k; 
	string s;
	char c1, c2;
	cin >> k >> s >> c1 >> c2;
	int ans = 0;
	for(int i = 0; i < s.size(); i ++)
	{
		if(s[i] != c1)
			continue;
		for(int j = i + 1; j < s.size(); j ++)
		{
			int len = j - i + 1;
			if(len >= k && s[j] == c2)
				ans ++;
		}
	}
	cout << ans << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	while(t--)
	solve();
}