88求助

P3741 小果的键盘

4 KKVK 样例错误
by st2aw1 @ 2022-07-14 20:43:03


```cpp #include<iostream> #include<map> #include<string.h> using namespace std; int main() { int n=0; cin>>n; char str[101]={0}; for(int i=0;i<n;i++) { cin>>str[i]; } int m=0; for(int i=0;i<n-1;i++) { if(i<n-2) { if(str[i]=='V' && str[i+1]=='V' && str[i+2]=='V') { str[i+1]='K'; break; } else if(str[i]=='K' && str[i+1]=='K' && (i==0||str[i-1]=='K'))//判定规则加一条; { str[i]='V';//改变的位置换一下; break; } } else if(i==n-2) { if(str[i]=='V' && str[i+1]=='V') { str[i+1]='K'; break; } else if(str[i]=='K' && str[i+1]=='K') { str[i]='V'; break; } } } for(int i=0;i<n-1;i++) { if((str[i]=='V' && str[i+1]=='K')) m++; } cout<<m; }
by st2aw1 @ 2022-07-14 20:51:47


|