80分求助
查看原帖
80分求助
1047386
ZTT1014楼主2024/4/2 17:38
#include<iostream>
using namespace std;
string str;
int x,n;
int main(){
	cin>>n;
	cin>>str;
	int f=1;
	for(int i=0;i<n-1;i++){
		if(str[i]=='V'&&str[i+1]=='K'){
			x++;
		}else if(/*i!=0&&*/str[i]=='V'&&f!=0){
			x++;
			str[i+1]='K';
			f=0;
		}else if(i!=0&&str[i-1]!='V'&&str[i]=='K'&&f!=0){
			x++;
			str[i-1]='V';
			f=0;
		}
	}
	cout<<x;
	return 0;
} 
2024/4/2 17:38
加载中...