Pagini recente » Cod sursa (job #2301433) | Cod sursa (job #2039971) | Cod sursa (job #1999670) | Cod sursa (job #2901725) | Cod sursa (job #1325728)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
int n,a[100],st,dr,m;
void citire(){
f>>n;
for(int i=1;i<=n;i++)f>>a[i];
}
int cautbin0(int x){
st=1;
dr=n;
while(st<dr){
m=st + (dr-st+1)/2;
if(a[m]>x)dr=m-1;
else st=m;
}
if(a[st]!=x)return -1;
return st;
}
int cautbin1(int x){
st=1;
dr=n;
while(st<dr){
m=st + (dr-st+1)/2;
if(a[m]>x)dr=m-1;
else st=m;
}
return st;
}
int cautbin2(int x){
st=1;
dr=n;
while(st<dr){
m=st + (dr-st+1)/2;
if(a[m]<x)st=m+1;
else dr=m;
}
return st;
}
int main()
{
int m,o,v;
citire();
f>>m;
for(int i=1;i<=m;i++){
f>>o>>v;
if(o==0)g<<cautbin0(v)<<'\n';
if(o==1)g<<cautbin1(v)<<'\n';
if(o==2)g<<cautbin2(v)<<'\n';
}
return 0;
}