fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. typedef long long ll;
  4. using namespace std;
  5.  
  6. void solve() {
  7. string s;
  8. cin>>s;
  9. int x =0;
  10. int y=0;
  11. int n=s.size();
  12. for(int i=0;i<n;i++){
  13. if(s[i]=='0'){
  14. x=max(x,y);
  15. y=0;
  16. continue;
  17. }
  18. y++;
  19. }
  20. x=max(x,y);
  21. if(x>3){
  22. int k=3*(n-2);
  23. cout<<k<<endl;
  24. }
  25. else{
  26. cout<<(2*(max(0ll,x-1)))<<endl;
  27. }
  28.  
  29. }
  30.  
  31. signed main() {
  32. int t;
  33. cin >> t;
  34. while (t--) {
  35. solve();
  36. }
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5288KB
stdin
5
0
1
101
011110
101010
stdout
0
0
0
12
0