Pagini recente » Cod sursa (job #1157384) | Cod sursa (job #89245) | Cod sursa (job #2828011) | Cod sursa (job #984361) | Cod sursa (job #1018323)
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n, v[10100100], k, x, y, poz;
int cbin(int a, int b){
int m=(a+b)/2;
//cout<<a<<' '<<b<<'\n';
if(a<b){
if(v[m]==y) poz=m, cbin(m+1, b);
if(v[m]<y) cbin(m+1, b);
if(v[m]>y) cbin(a, m-1);
}
if(!poz) return -1;
else return poz;
}
int main()
{
f>>n;
for(int i=1; i<=n; ++i)
f>>v[i];
f>>k;
for(int i=0; i<k; ++i){
f>>x>>y;
if(x==0){poz=0; g<<cbin(1, n); return 0;}
else if(x==1) return 0;
else return 0;
}
return 0;
}