-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path67020048.cpp
69 lines (68 loc) · 1.16 KB
/
67020048.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
int black=0;
for(int i=0;i<n;i++)
{
char s;
scanf("%c",&s);
if(s=='\n')
{
i--;
continue;
}
if(s=='W')
arr[i]=1;
if(s=='B')
{
arr[i]=0;
black++;
}
}
if(black%2==1 && ((n-black)%2)==1 )
{
cout<<-1<<endl;
return 0;
}
queue<int> data;
if(black%2==1)
{
if(arr[0]==1)
{
arr[0]=!arr[0];
arr[1]=!arr[1];
data.push(1);
}
}
else if( (n-black)%2==1 )
{
if(arr[0]==0)
{
arr[0]=!arr[0];
arr[1]=!arr[1];
data.push(1);
}
}
for(int i=1;i<n-1;i++)
{
if(arr[i]!=arr[i-1])
{
data.push(i+1);
arr[i]=!arr[i];
arr[i+1]= !arr[i+1];
}
}
cout<<data.size()<<endl;
while(!data.empty())
{
cout<<data.front()<<" ";
data.pop();
}
return 0;
}