b.cpp (963B)
1 #include <iostream> 2 #include <vector> 3 #include <unordered_set> 4 #include <unordered_map> 5 #include <algorithm> 6 #include <queue> 7 8 #define ll long long 9 10 using namespace std; 11 12 int main() { 13 int testCases; 14 string current = ""; 15 cin >> testCases; 16 17 // red and blue, start red 18 // color makes it switch so red := (index%2 == 0) 19 // can switch manually (including before start) 20 21 // find min number of manual switches to write the string 22 23 for(int z = 0; z < testCases; ++z) { 24 bool red = true; 25 int nu = 0; 26 27 cin >> nu; 28 cin >> current; 29 30 int switches = 0; 31 32 for(int i = 0; i < current.size(); ++i) { 33 if(current[i] == 'B' && red) { 34 switches += 1; 35 red = false; 36 } else if(current[i] == 'R' && !red) { 37 switches += 1; 38 red = true; 39 } 40 red = !red; 41 } 42 cout << switches << endl; 43 } 44 }