Advertisement
Ankit_132

C

Apr 17th, 2024
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int t;
  6.     cin>>t;
  7.    
  8.     while(t--){
  9.         int n;
  10.         string s;
  11.         cin>>n>>s;
  12.        
  13.         vector<int> ans;
  14.        
  15.         for(int i=0; i<n; i+=2){
  16.             if(s[i] != s[i+1]){
  17.                 if(ans.size()==0 || s[ans.back()]==s[i+1])
  18.                     ans.push_back(i);
  19.                 else
  20.                     ans.push_back(i+1);  
  21.             }
  22.         }
  23.        
  24.         cout<<ans.size()<<"\n";
  25.         for(auto e: ans)    cout<<e+1<<" ";
  26.         cout<<"\n";
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement