Files
python/TangDou/LuoGuBook/P3741.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

31 lines
741 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int maxN;
/**
* 功能获取字符串中有多少个VK
*/
int getVkCount(string s) {
int cnt = 0;
for (int i = 0; i < s.size() - 1; i++) //注意这里的-1
if (s[i] == 'V' && s[i + 1] == 'K') cnt++;
return cnt;
}
int main() {
int n;
string s;
cin >> n >> s;
//计算一下原始的VK个数
maxN = getVkCount(s);
//变换
for (int i = 0; i < s.size(); i++) {
string s1 = s;
s1[i] = s1[i] == 'K' ? 'V' : 'K';//该个变换一下,这个三元表达式用的很舒服~
//重新计算最大个数值
maxN = max(maxN, getVkCount(s1));
}
printf("%d", maxN);
return 0;
}