Advertisement
Rofyda_Elghadban1

Untitled

Sep 20th, 2023
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1.  #include <bits/stdc++.h>
  2.  #define ll long long
  3.  #define ull unsigned long long
  4.  #define pi 3.141592654
  5.  #define NUM 1e18
  6.  #define Mod  1'000'000'007
  7.  #define fixed(n) fixed<<setprecision(n)
  8.  #define cin(v) for(auto &i:v) cin >> i ;
  9.  #define cout(v) for(auto &i:v) cout << i  <<" ";
  10.  #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11.  #define small(x) (x>=97&&x<=122)
  12.  #define capital(x) (x>=65&&x<=90)
  13.  #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14.  #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15.  #define all(v) ((v).begin()), ((v).end())
  16.  #define allr(v) ((v).rbegin()), ((v).rend())
  17.  #define updmax(a,b) a=max(a,b)
  18.  #define updmin(a,b) a=min(a,b)
  19.  #define ceil(a,b) ((a/b)+(a%b?1:0))
  20.  /* asc -> 1 2 3 ,des -> 3 2 1 */
  21.  /***********************************************************************************/
  22.  using namespace std;
  23.  void Rofyda_Elghadban(){
  24.   #ifndef ONLINE_JUDGE  
  25.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26.    #endif
  27.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  28.  }
  29.  
  30.  void solve(){
  31.  int t;
  32.  cin>>t;
  33.  while(t--){
  34.   string s,t1="010",t2="101";
  35.   cin>>s;
  36.   int counter1=0,counter2=0,ones=0,zeros=0;
  37.   for(int i=0;i<s.size();i++){
  38.     if(s[i]=='1'){
  39.       ones++;
  40.     }else if(s[i]=='0'){
  41.       zeros++;
  42.     }
  43.     if(s[i]==t1[counter1]){
  44.       counter1++;
  45.     }if(s[i]==t2[counter2]){
  46.       counter2++;
  47.     }
  48.   }
  49.   if(counter1==3||counter2==3){
  50.     cout<<min(zeros,ones)<<"\n";
  51.   }else{
  52.     cout<<"0"<<"\n";
  53.   }
  54.  }
  55.  }
  56.  
  57.  int main(){
  58.   Rofyda_Elghadban();
  59.   solve();
  60.  
  61.   return 0;
  62.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement