自己尝试运行了,答案和标准答案是一样的,但为什么却没过?
以下为源代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("123.in", "r", stdin);
freopen("123.out", "w", stdout);
#endif
int n, ans = 0, cnt;
string s, word;
scanf("%d\n", &n);
getline(cin, s);
cnt = s.find("VK");
if (cnt == -1) {
for (int i = 0; i < n; i++){
if (s[i] == s[i + 1]) {
cout << 1 <<endl;
return 0;
}else {
cout << 0 << endl;
return 0;
}
}
}
while (cnt != -1) {
ans++;
cnt = s.find("VK", cnt + 1);
}
while (cnt == -1) {
int a = s.find("VV", a + 1);
int b = s.find("KK", b + 1);
if (a != -1) {
s[a + 1] -= 11;
int ans1 = 0, c = s.find("VK");
while (c != -1){
ans1++;
c = s.find("VK", c + 1);
if (ans1 > ans) {
cout << ans1 <<endl;
return 0;
}
}
s[a + 1] += 11;
}
if (b != -1) {
s[b] += 11;
int ans2 = 0, d = s.find("VK");
while (d != -1){
ans2++;
d = s.find("VK", d + 1);
if (ans2 > ans) {
cout << ans2 <<endl;
return 0;
}
}
s[b] -= 11;
}
if (a == -1 && b == -1) {
cout << ans <<endl;
return 0;
}
}
return 0;
}