求助!这题我自己搞不定了
#include <bits/stdc++.h>
using namespace std;
long a[1000]={0};
int halfind(long x,int lbound,int rbound){
int rank=lbound+ceil((rbound-lbound)/2);
if(rbound==lbound){
return a[lbound];
}
if(x>a[rank]){
return halfind(x,rank,rbound);
}
else if(x<=a[rank]){
return halfind(x,lbound,rank);
}
}
int main(){
int n,m;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
cin>>m;
for(int i=0;i<m;i++){
int t;
cin>>t;
cout<<halfind(t,0,n-1)<<endl;
}
return 0;
}