fork download
  1. // Converted from python to c++ using LLMs for practice purposes
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9.  
  10. int t;
  11. cin >> t;
  12.  
  13. while (t--) {
  14. string s;
  15. cin >> s;
  16.  
  17. int n = s.size();
  18. int x = s[0] - '0', f1 = 0, f2 = 0, c = 0;
  19.  
  20. for (int i = 0; i < n; i++) {
  21. int z = s[i] - '0';
  22.  
  23. if (x == z) c++;
  24. else {
  25. if (i > 1 && c == 1) f1 = 1;
  26. if (c > 2) f2 = 1;
  27. x = z;
  28. c = 1;
  29. }
  30. }
  31.  
  32. if (c > 2) f2 = 1;
  33. cout << 1 + f1 + f2 << '\n';
  34. }
  35. }
  36.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty