This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#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;