Finding Elements
[Codeup 1934] find X
Enter a number n, and then enter the n value is different, then a value of input x, the output value in the array subscript (from 0, if the array is output 1).
Input
test data set multiple, input n (1 <= n <= 200), then the number of inputs n, and the input x.
Output
for each set of input, output.
Sample input
4
1 2 3 4
3
sample output
2
resolved: OJ seem bad, did not return a result, the current sample test correctly
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> v(n);
for(int i = 0;i<n;++i) cin>>v[i];
int m,flag=-1;
cin>>m;
for(int i=0;i<n;i++){
if(v[i]==m) flag=i;
}
cout<<flag;
return 0;
}