fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5. int n;
  6. string s;
  7. cin >> n >> s;
  8. int c = 0, ans = 0;
  9. char x = s[0];
  10.  
  11. for (char z : s) {
  12. if (x == z) c++;
  13. else {
  14. ans += c/3;
  15. x = z; c = 1;
  16. }
  17. }
  18. cout << ans+c/3 << '\n';
  19. }
  20.  
  21. int main() {
  22. int t;
  23. cin >> t;
  24. while (t--) solve();
  25. }
  26.  
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty