提交时间:2020-11-18 18:56:07

运行 ID: 9758

#include<bits/stdc++.h> using namespace std; int a[100010]; int find(int begin,int end,int d){ if(begin>end){ return -1; } int mid=(begin+end)/2; int ret=-1; if(a[mid]==d){ ret=mid; }else if(a[mid]>d){ ret=find(begin,mid-1,d); }else if(a[mid]<d){ ret=find(mid+1,end,d); } return ret; } int main(){ int n=0,m=0; cin>>n>>m; for(int i=0;i<=n;i++){ cin>>a[i]; } int d=0,k=0; for(int i=0;i<=m;i++){ cin>>d; k=find(0,n-1,d); cout<<k<<endl; } return 0; }