-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpyDetected.cpp
More file actions
60 lines (55 loc) · 1.34 KB
/
SpyDetected.cpp
File metadata and controls
60 lines (55 loc) · 1.34 KB
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
60
/*
problem statement:
You are given an array a consisting of n (n≥3) positive integers.
It is known that in this array, all the numbers except one are the same (for example, in the array [4,11,4,4] all numbers except one are equal to 4).
Print the index of the element that does not equal others. The numbers in the array are numbered from one.
*/
#include<iostream>
using namespace std;
int main()
{
int t;
int* arr;
cin >> t;
int size;
for (int T = 0; T < t; T++)
{
cin >> size;
arr = new int[size];
for (int j = 0; j < size; j++)
cin >> arr[j];
if (size == 1)
{
cout << "1\n";
}
else if (size == 2)
{
cout << "1\n";
}
else if (arr[1] == arr[2] && arr[0] != arr[1])
{
cout << "1\n";
}
else if (arr[0] == arr[2] && arr[0] != arr[1])
{
cout << "2\n";
}
else if(arr[0] == arr[1] && arr[0] != arr[2])
{
cout << "3\n";
}
else
{
for (int i = 3; i < size; i++)
{
if (arr[i] != arr[i - 1])
{
cout << i + 1 << "\n";
break;
}
}
}
delete[] arr;
}
return 0;
}