jeudi 7 mai 2020

What is my mistake in this implementation of string and the if statements in c++?

#include<bits/stdc++.h>
using namespace std;

int main()
{
        long long int n;
        string s;
        cin>>n;   // 3
        cin.ignore();
        long long int siz = 2*n, Ascore = 0, Bscore = 0;
        cin>>s; // 101011
        for(int i = 0; i < siz; i++ )
        {

            if((i%2 == 0) && (s[i] == 1))
                Ascore++;
            if((i%2 == 1) && (s[i] == 1))
                Bscore++;
            if(abs(Ascore-Bscore) == 2)
                cout<<i+1<<"\n";
            if((i % 2 == siz-1) && (Ascore == Bscore))
                cout<<i+1<<"\n";


        }

}

I have given the value of n as 3 I have given the value of the string as 101011 The value of Ascore and Bscore is always zero and is not incrementing and nothing is being printed in the output.

Aucun commentaire:

Enregistrer un commentaire