Pagini recente » Cod sursa (job #485558) | Cod sursa (job #2667364) | Cod sursa (job #2027240) | Cod sursa (job #948822) | Cod sursa (job #1320956)
//#include <fstream>
#include <iostream>
using namespace std;
//ifstream fin("cautbin.in");
//ofstream fout("cautbin.out");
int i,val,n,x,stop,a[100],m;
int binary_searchh(int val)
{
int i, step;
for (step = 1; step < n; step <<= 1);
for (i = 0; step; step >>= 1)
if (i + step < n && a[i + step] <= val)
i += step;
return i;
}
int binary_searchhh(int val)
{
int i, step;
for (step = 1; step < n; step <<= 1);
for (i = 0; step; step >>= 1)
if (i + step < n && a[i + step] < val)
i += step;
return i+1;
}
int main()
{
cin>>n;
for(i=1;i<=n;++i)
cin>>a[i];
cin>>m;
i=1;
while(i<=m)
{
cin>>x;
if(binary_searchh(x)>0)
cout<<"0)"<<binary_searchh(x)<<"\n";
else
cout<<"0)"<<-1<<"\n";
cout<<"1)"<<binary_searchh(x)<<"\n";
if(binary_searchhh(x)>0)
cout<<"2)"<<binary_searchhh(x)<<"\n";
else
cout<<"2)"<<-1<<"\n";
}
return 0;
}