-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIQtest.cpp
More file actions
50 lines (46 loc) · 938 Bytes
/
IQtest.cpp
File metadata and controls
50 lines (46 loc) · 938 Bytes
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
/*Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others.
Bob observed that one number usually differs from the others in evenness.
Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.*/
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* arr = new int[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
if (arr[0] % 2 == 0 && arr[1] % 2 == 1 && arr[2] % 2 == 1)
{
cout << "1";
return 0;
}
if (arr[0] % 2 == 1 && arr[1] % 2 == 0 && arr[2] % 2 == 0)
{
cout << "1";
return 0;
}
if (arr[0] % 2 == 0)
{
for (int i = 1; i < n; i++)
{
if (arr[i] % 2 != 0)
{
cout<<i+1;
break;
}
}
}
else
{
for (int i = 1; i < n; i++)
{
if (arr[i] % 2 == 0)
{
cout << i + 1;
break;
}
}
}
return 0;
}