这是我原先的代码(截取部分):
#include<bits/stdc++.h>
using namespace std;
int q,lcs,sum=1,p;
char cs[3000010],c,x,tmp[3];
int main()
{
cin>>q;
cin.getline(tmp,2);
cin.getline(cs+1,3000000);
lcs=strlen(cs+1);
x=cs[1];
for(int i=2;i<=lcs;i++)
{
if(cs[i]!=x) x=cs[i],sum++;
}
cout<<(sum+1)/2<<endl;
return 0;
}
大家可以把我上面的代码的注释给去掉(除输入输出的样例外),可以发现把样例代入后在 Dev-C++中的输出与在洛谷 IDE 中的不一样,经过我的发现,是第 20 行中的 lcs 在编译器中比 IDE 中多了 1,所以不知道为什么,望谷民求解。