@[weiyuangji](/user/760712) 你要改变一个字母的可能性没有考虑,要考虑一下。
我的代码:
```cpp
#include <iostream>
#include <string>
using namespace std;
int n, ans;
string s;
int main() {
cin >> n;
cin >> s;
int num = 0;
for (int i = 0; i < n; i ++ ) if (s[i] == 'V') if (s[i + 1] == 'K') num ++ ;
ans = max(ans, num);
for (int i = 0; i <= n; i ++ ) {
num = 0;
if (s[i] == 'V') {
s[i] = 'K';
for (int j = 0; j < n; j ++ ) if (s[j] == 'V') if (s[j + 1] == 'K') num ++ ;
ans = max(ans, num);
s[i] = 'V';
} else if (s[i] == 'K') {
s[i] = 'V';
for (int j = 0; j < n; j ++ ) if (s[j] == 'V') if (s[j + 1] == 'K') num ++ ;
ans = max(ans, num);
s[i] = 'K';
}
}
cout << ans << endl;
return 0;
}
```
by ttltony @ 2023-03-21 16:28:10
@[ttltony](/user/709380) OK
by _fox_ @ 2023-03-23 17:24:26
@[weiyuangji](/user/760712) thanks
by ttltony @ 2023-03-24 13:10:52