It's probably a stupid problem, but I can't get it right. It's supposed to look like that:
Input:
2 // amount of data sets
5 // amount of numbers in array
1 2 3 1 5 //array elements
3 //searched element index +1
4 //and so on
4 3 2 1
5
Output:
3
None
But if there is no searched value program returns "98779" instead of "NONE" I have no idea whats wrong. Here is the code
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int tab[100000];
int x,y,z,elem;
cin >> x;
for(int i=0;i<x;i++)
{
cin >>y;
for(int j=0;j<y;j++)
{
cin >> z;
tab[j]=z;
}
cin >> elem;
int n = sizeof(tab)/sizeof(tab[0]);
auto itr = find(tab, tab + n, elem);
if (itr != end(tab))
{
cout << distance(tab,itr)+1;
}
else
{
cout << "NONE";
}
}
return 0;
}