-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2N+1.cpp
More file actions
46 lines (34 loc) · 730 Bytes
/
Copy path2N+1.cpp
File metadata and controls
46 lines (34 loc) · 730 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
#include <bits/stdc++.h>
using namespace std;
void recur(int k,const vector<int>& arr,int low,int high){
int index = low + (high - low )/2 ;
if( arr[index] == k){
cout<<index+1<<endl;
return;
}else if( low > high ){
cout<<-1<<endl;
return;
}else if( arr[index] < k ){
recur(k,arr,index+1,high);
}else{
recur(k,arr,low,index-1);
}
}
int main(int argc, char const *argv[])
{
int l,k,s;
vector<int> arr;
cin>>l;
for (size_t i = 0; i < l; i++)
{
cin>>k;
arr.push_back(k);
}
cin>>s;
for (size_t i = 0; i < s; i++)
{
cin>>k;
recur(k,arr,0,l-1);
}
return 0;
}