TEMA

Runtime error

tahmid preguntado 3 months ago

//why am i getting runtime error? //i tried to print all i values to see whether i am accessing array index which is not valid. But it was ok.

include

using namespace std;

int main(){ long long n,p,i=0,q=0,sheep=0; cin>>n; long long star[n],attack[n];

p=n;
while(n--){
    cin>>star[i];
    sheep+=star[i];
    attack[i]=0;
    i++;
}

i=0;
while(i>=0&&i<p){
    if(star[i]%2==0&&star[i]>=0){
        if(attack[i]==0){
            attack[i]=1;
            q++;
        }
        if(star[i]>0){
            star[i]--;
            sheep--;
            i--;
        }
        else if(star[i]==0){
            i--;
        }

    }
    else if(star[i]%2!=0&&star[i]>0){
        if(attack[i]==0){
            attack[i]=1;
            q++;
        }
        star[i]--;
        sheep--;
        i++;
    }
}

cout<<q<<" "<<sheep<<endl;

return 0;

}

Este tema fue resuelto y no puede recibir nuevas respuestas.