fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int p;
  6. int n,x,i,ar[n-1];
  7. string s;
  8. cin>>n>>s;
  9. char c[n+1];
  10. strcpy(c, s.c_str());
  11. for(i=0;i<n-1;i++)
  12. {
  13. if(c[i]=='B')
  14. {
  15. c[i]='W';
  16. if(c[i+1]=='B')
  17. c[i+1]='w';
  18. else
  19. c[i+1]='B';
  20. x++;
  21. ar[i]=i;
  22. }
  23. }
  24. if(c[i]=='B')
  25. {
  26. cout<<-1;
  27. }
  28. else{
  29. cout<<x<<endl;
  30. for(int i=0;i<n-1;i++)
  31. cout<<ar[i]<<" ";
  32. }
  33. }
  34.  
Success #stdin #stdout 0s 4384KB
stdin
8
BWWWWWWB
stdout
7
0 1 2 3 4 5 6