lanqiao3514 字串简写

This commit is contained in:
2025-03-16 15:57:24 +08:00
parent 1c942ba9a1
commit 95984b41d3
2 changed files with 54 additions and 0 deletions

33
14lanqiao/test7-1.cpp Normal file
View File

@@ -0,0 +1,33 @@
// lanqiao3514 字串简写(枚举)
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int k;
string s;
char a, b;
cin >> k >> s >> a >> b;
vector<int> ft, bk;
for(int i = 0; i < s.size(); i++){
if(a == s[i]) ft.push_back(i);
}
for(int i = 0; i < s.size(); i++){
if(b == s[i]) bk.push_back(i);
}
int ans = 0;
for(int i = 0; i < ft.size(); i++){
for(int j = 0; j < bk.size(); j++){
if( bk[j] - ft[i] + 1 < k) continue;
else{
ans += bk.size() - j; // 1 2 1 1 1
break; // 找到一个符合条件的,直接把后面全加上,然后跳出此次循环
}
}
}
cout << ans << endl;
return 0;
}
/* samples -> 6
4
abababdb a b
*/