一个暴力代码成功的JUDGE了3min
查看原帖
一个暴力代码成功的JUDGE了3min
1234324
god_std楼主2025/6/21 22:26
#include <bits/stdc++.h>
using namespace std;

int n, f;
string s, t;
set<string> answer;

void updateAnswer() {
	map<string, int> eCount;
	for (size_t i = 0; i + 2 < t.size(); i++)
		if (t[i] != t[i + 1] && t[i + 1] == t[i + 2])
			eCount[t.substr(i, 3)]++;
	for (auto i : eCount)
		if (i.second >= f)
			answer.insert(i.first);
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
	cin >> n >> f >> s, t = s;
	updateAnswer();
	for (int i = 0; i < n; i++) {
		for (t[i] = 'a'; t[i] <= 'z'; t[i]++)
			if (t[i] != s[i])
				updateAnswer();
		t[i] = s[i];
	}
	cout << answer.size() << '\n';
	for (auto i : answer)
		cout << i << '\n';
    return 0;
}
2025/6/21 22:26
加载中...