#include <iostream>
#include <algorithm>
using namespace std;
struct bowlroad
{
int p;
int bowl;
};
int cmp(bowlroad a,bowlroad b)
{
return a.bowl<b.bowl;
}
int n,q;
bowlroad *bottle;
int *need,*point;
int main()
{
cin>>n;
bottle=new bowlroad[n];//申请数组
for (size_t i = 0; i < n; i++)
{
cin>>bottle[i].bowl;
bottle[i].p=i;
}
cin>>q;
need=new int[q];point=new int[q];//依旧是申请数组
fill(point,point+q,0);//赋值数组
for (size_t i = 0; i < q; i++)
{
cin>>need[i];
}
sort(bottle,bottle+n,cmp);//排序
for (size_t i = 0; i < q; i++)
{
int l=0,r=n;
while (l<=r)
{
int mid=(l+r)>>1;
if (bottle[mid].bowl==need[i])
{
point[i]=bottle[mid].p;
}
else if(bottle[mid].bowl<need[i])
{
l=mid+1;
}
else
{
r=mid-1;
}
}
}
for (size_t i = 0; i < q; i++)
{
cout<<point[i]<<endl;
}
return 0;
}
为什么输不出???