-
Notifications
You must be signed in to change notification settings - Fork 1
/
1367B.cpp
36 lines (36 loc) · 861 Bytes
/
1367B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Even Array.
#include <bits\stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int t, len, evenCount, oddCount, count;
cin >> t;
while (t--)
{
evenCount = oddCount = count = 0;
cin >> len;
int arr[len];
for (int i = 0; i < len; i++)
{
cin >> arr[i];
if (arr[i] % 2 == 0)
evenCount++;
else
oddCount++
}
if (evenCount != oddCount && len % 2 == 0)
cout << -1 << "\n";
else if (evenCount != oddCount + 1 && len % 2 != 0)
cout << -1 << "\n";
else
{
for (int i = 0; i < len; i += 2)
{
if (arr[i] % 2 != 0)
count++;
}
cout << count << "\n";
}
}
return 0;
}