Pagini recente » Istoria paginii runda/oji-2017 | Cod sursa (job #435216) | Cod sursa (job #454431) | Cod sursa (job #1549298) | Cod sursa (job #1320960)
#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()
{
fin>>n;
for(i=1;i<=n;++i)
fin>>a[i];
fin>>m;
i=1;
while(i<=m)
{
fin>>x;
if(binary_searchh(x)>0)
fout<<"0)"<<binary_searchh(x)<<"\n";
else
fout<<"0)"<<-1<<"\n";
fout<<"1)"<<binary_searchh(x)<<"\n";
if(binary_searchhh(x)>0)
fout<<"2)"<<binary_searchhh(x)<<"\n";
else
fout<<"2)"<<-1<<"\n";
}
return 0;
}