Mahasena(Beginers)

#include
using namespace std;
int even(int number)
{
if(number%2==0)
return 1;
else
return 0;
}
int main()
{
int N;
cin>>N;
int *arr = new int[N];
int count=0,count1=0;
for(int i=1;i<=N;i++)
{
cin>>arr[i];
if(even(arr[i])==1)
{
count++;
}
else
count1++;
}
if(count < count1)
{
cout<<“NOT READY”<<endl;
}
else
{
cout<<“READY FOR BATTLE”<<endl;
}
return 0;

}

What’s wrong in this code ??
Please tell me, because this code is matching all the outputs of the problem.
Problem Name : Mahasena (Beginers)

If you have an array of size N then you can access array elements from index 0 to N-1.But you are accessing element at index N so declare an array of size N+1.

1 Like

Apart from what @hruday968 said, you are using the wrong condition.

The question states that the count of lucky (even) soldiers should be strictly greater than the count of unlucky (odd) soldiers, i.e. count > count1.

So, change the condition in your code from this

if(count < count1)

to this

if(count <= count1)
1 Like

i have started my array from index 1

thank you it worked

so what???