fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7. while(t--)
  8. {
  9. int n,c=0,d=0;
  10. cin >> n;
  11. string s;
  12. cin >> s;
  13. for(int i=0;i<n-1;i++)
  14. {
  15. if((s[i]=='0' && s[i+1]== '1'))
  16. {
  17. c++;
  18. }
  19. else if((s[i]=='0' && s[i+1]== '1'))
  20. {
  21. d++;
  22. }
  23. }
  24. int a = min(c,d);
  25. cout << a << endl;
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
5
0 0 1 1 1
1
0
5
1 1 0 0 1
2
1 0
5
1 0 1 0 1 
stdout
0
0
0
0
0