Changing Bits Discussions | Algorithms | HackerRank
  • + 0 comments

    anybody please help something. wrong in this code

    include

    include

    include

    include

    using namespace std;

    int main() { long int m,n,i,l=0,l2=0,j; int temp,c=0; string st; cin>>m>>n;

    char u[n][m+10],a[m],b[m],t;
    
    cin>>a>>b;
    
    for(i=0;i<n;i++)
    {
        cin>>u[i];
    }
        stringstream s;
    
    for(i=0;i<n;i++)
    {
    
        long int si=strlen(u[i]);
    
        for(j=0;j<5;j++)
        {
            st+=t;
        }
    
        if(st=="set_a")
        {
    
        for(j=6;u[i][j]<' ';j++)
        {
            t=u[i][j];
            s<<t;
            s>>temp;
            l=l*10+temp;
    
        }
    
        while(j<si)
        {
            t=u[i][j];
            s<<t;
            s>>temp;
            l2=l2*10+temp; 
        }
    
        a[si-l-1]=l2;
    }
    
    if(st=="set_b")
        {
    
        for(j=6;u[i][j]<' ';j++)
        {
            t=u[i][j];
            s<<t;
            s>>temp;
            l=l*10+temp;
    
        }
    
        while(j<si)
        {
            t=u[i][j];
            s<<t;
            s>>temp;
            l2=l2*10+temp; 
        }
    
        b[si-l-1]=l2;
    }
    if(st=="get_c")
    {
    
            vector<int> y;
            for(j=n;j>=0;j--)
            {
                if(a[j]=='1'&&b[j]=='1'&&c==1)
                {
    
                    y.push_back(1);
    
                }
    
                if(a[j]=='1'&&b[j]=='1'&&c==0)
                {
                    y.push_back(0);
                    c=1;
                }
    
                if((a[j]=='1' && b[j]=='0' && c==1)||(a[j]=='0' && b[j]=='1' && c==1))
                {
                    y.push_back(0);
    
                }
    
                if((a[j]=='1' && b[j]=='0' && c==0 )||(a[j]=='0' && b[j]=='1' && c==0)||(a[j]=='0' && b[j]=='0' && c==1))
                {
                    y.push_back(1);
                    c=0;
    
                }
    
                if((a[j]=='0' && b[j]=='0' && c==0 ))
                {
                    y.push_back(0);
    
                }
    
    
            }
    
        for(j=6;u[i][j]<' ';j++)
        {
            t=u[i][j];
            s<<t;
            s>>temp;
            l=l*10+temp;
    
        }
    
        cout<<y[si-l-1];
    
    }
    

    }

    }