using namespace std;
cin >> t;
cin >> n;
int a[n],odd = 0,even=0;
for (int i = 0; i < n; i++)
cin >> a[i];
if (a[i] % 2 != 0)
if (odd % 2 == 0 || even == 0)
cout << 1 << endl;
cout << 2 << endl;
Try taking two loops for initializing the array and checking for if it is odd or even
nothing changes in output.
i think mistake in problem.
if we consider case all numbers are odd in odd times
sum of 1+1 is even and add into 3
so it will be 5 answer will be 1.
so that’s why i inserted condition even==0 .
but i analyzed some codes which has correct answer
it shows me answer 2. try yourself.
if i delete even ==0 condition and put condition n==1
i also got correct answer.
Array need to be declare with fix size, if need the size to be changing, can consider to use dynamic size array, ie vector.
As for this case, you can have a fix value 12 or const int n = 12.
with this declaration, you will have a dedicate memory allocated without any rubbish data in it. Can try it.
There is no mistake in question. because you got this question wrong. They want to say that they chose an arbitrary pair of elements from the sequence such that their sum is even, deleted these two elements from the sequence, and inserted their sum into the sequence. means that if you have an array like [1,1,3], the sum of 1 + 1 is an even number, and you have to add that to the sequence (like [2,3], not as 2 + 3, and the final array is ). As a result, the minimum length is 2.
ok i now i got it
i will note this