Pagini recente » Cod sursa (job #3296358) | Cod sursa (job #2300759) | Cod sursa (job #1706237) | Cod sursa (job #1094605) | Cod sursa (job #2627326)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int N,v[100],M,intr,x;
int main()
{
fin>>N;
int poz=-1,mij;
for(int i=0;i<N;i++){
fin>>v[i];
}
fin>>M;
int st=1,dr=N;
while(M){
fin>>intr>>x;
if(intr==0){
while(st<=dr)
{
mij=(st+dr)/2;
if(v[mij]==x)
{
poz=mij;
st=mij+1;
}
else if(v[mij]<x)
{
st=mij+1;
}
else
dr=mij-1;
}
fout<<poz+1<<"\n";
M--;
st=1;
dr=N;
}
if(intr==1){
while(st<=dr)
{
mij=(st+dr)/2;
if(v[mij]<=x)
{
poz=mij;
st=mij+1;
}
else if(v[mij]<x)
{
st=mij+1;
}
else
dr=mij-1;
}
fout<<poz+1<<"\n";
M--;
st=1;
dr=N;
}
if(intr==2){
while(st<=dr)
{
mij=(st+dr)/2;
if(v[mij]>=x)
{
poz=mij;
dr=mij-1;
}
else if(v[mij]<x)
{
st=mij+1;
}
else
dr=mij-1;
}
fout<<poz+1<<"\n";
M--;
st=1;
dr=N;
}
}
}