EMTY2 - Can You Make It Empty 2

  Problem Link : EMTY2 


👉 Hint : Think about substrings and their concatenation

 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    int k=1;
    while(t--)
    {
       string s,s1,s2;
       cin>>s;
       int i=0;
       while(s.length()>2 && i<s.length()-2)
       {
            if(s[i]=='1' && s[i+1]=='0' && s[i+2]=='0')
            {
                s1=s.substr(0,i);
                s2=s.substr(i+3,s.length()-i-3);
                s=s1+s2;
                if(i>=2)
                    i-=2;
                else
                    i=0;
            }
            else
                i++; 
       }
       if(s.length()==0)
           cout<<"Case "<<k<<": yes"<<endl;
       else
           cout<<"Case "<<k<<": no"<<endl;
       k++;    
    }
} 

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!