具体见代码
#include<bits/stdc++.h>
using namespace std;
int T,n;
string str;
void update(char& c){
if(c=='B') c='W';
else c='B';
}
bool check(char c){
vector<int>v;//存方案
string s=str;
for(int i=0;i+1<n;i++){
if(s[i]!=c){
update(s[i]);
update(s[i+1]);
v.push_back(i);
}
}
if(s.back()!=c) return 0;//注意检查最后字符串的一个字符是否符合要求
cout<<v.size()<<endl;
for(int i:v) cout<<i+1<<' ';//?注意编号从1开始
if(v.size()) cout<<endl;//如果修改次数为0,只用换行一次
return 1;
}
int main(){
cin>>T;
while(T--){
cin>>n>>str;
if(!check('B')&&!check('W')) puts("-1");
}
}