笑死,我居然会求助一道红题

P3741 小果的键盘

`for(int i=0;i<n;i++)`
by yurongyi @ 2024-03-04 19:21:07


@[yurongyi](/user/945607) 还是过不了, $96pts$ ,错的是刚才没错的
by __Rickysun__ @ 2024-03-04 19:32:00


@[Rickysun](/user/824205) 您好,一下是 hack 数据: ``` input: 2 VK output: 1 yours: 0 ``` 问题出在开始 $d$ 并没有赋值。 ```cpp #include<bits/stdc++.h> using namespace std; int n,ma=-1; string s,d; int count(){ int cnt=0,p=d.find("VK"); while(p!=-1){ cnt++; p=d.find("VK",p+1); } return cnt; } int main() { cin>>n>>s; d=s; ma=count(); for(int i=0;i<n;i++){ d=s; if(d[i]=='V') d[i]='K'; else d[i]='V'; ma=max(count(),ma); } cout<<ma; return 0; } ```
by _qingshu_ @ 2024-03-04 20:06:37


@[Rickysun](/user/824205) 欸,等等,虽然下面的代码确实过了,但是我好像改了什么奇怪的地方?
by _qingshu_ @ 2024-03-04 20:08:05


@[Rickysun](/user/824205) 哦,知道了,你下标还写错了。
by _qingshu_ @ 2024-03-04 20:08:44


@[_qingshu_](/user/602803) 啊,懂了,蟹蟹,关注了
by __Rickysun__ @ 2024-03-04 20:28:24


|