88分求助
查看原帖
88分求助
792359
Hayaizo楼主2022/10/7 15:34
#include<iostream>
#include<string>
using namespace std;

int main(void) {
	int n = 0;
	string str;
	cin >> n;
	cin >> str;
	int cnt = 0;
	int num = 0;
	int nextpos = str.find("VK");
	for (int i = 0; i < n; i++) {
		while (nextpos != -1) {
			cnt++;
			nextpos=str.find("VK", nextpos + 1);
			num += 2;
		}
		if (num == n) {
			break;
		}
	}
	for (int i = 0; i < n; i++) {
		if (num == n) {
			break;
		}
		if (str[i] == 'V' && str[i + 1] == 'V' || str[i] == 'K' && str[i + 1] == 'K') {
			cnt++;
			break;
		}
	}
	cout << cnt << endl;
	return 0;
}
2022/10/7 15:34
加载中...