-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevenArray.c
59 lines (46 loc) · 1.08 KB
/
evenArray.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//incomplete
#include<stdio.h>
int findmin(int num1,int num2){
if(num1 <= num2){
return num1;
}else{
return num2;
}
}
int main(){
int t;
scanf("%d",&t);
for(int i = 0; i < t; i++){
int n;
scanf("%d",&n);
int arr[n];
int countOfZeroAtEven=0, countOfOneAtOdd=0;
int wrongZero = 0, wrongOne = 0;
for(int j = 0; j < n; j++){
int temp;
scanf("%d",&temp);
arr[i] = temp;
if(j%2 == 0 && temp%2 != 0){
wrongOne += 1;
}else{
wrongZero += 1;
}
}
if(n%2 == 0){
if(wrongOne == wrongZero){
printf("%d\n",wrongOne);
}else{
printf("%d\n",-1);
}
}else{
if(wrongOne == 0 && wrongZero == 0){
printf("%d",0);
}else if(wrongOne == wrongZero){
printf("%d\n",wrongOne);
}else{
printf("%d\n",-1);
}
}
}
return 0;
}