Cod sursa(job #2662753)
| Utilizator | Data | 24 octombrie 2020 13:50:54 | |
|---|---|---|---|
| Problema | Cautare binara | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.86 kb |
#include <fstream>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int M,N,S,v[100000],T,x,Max;
int main()
{fin>>N;
S=1;
while (S<=N)
{fin>> v[S];
S++;
}
fin>>M;
while (M!=0)
{fin>>T>>x;
if (T==0)
{S=1;
while (S<N and v[S]<=x)
{if (v[S]==x)
Max=S;
S++;
}
if (Max>0)
fout<<Max<<endl;
else
fout<<-1;
}
if (T==1)
{ S=1;
while (S<N and v[S]<=x)
S++;
fout<<S-1<<endl;
}
if (T==2)
{S=1;
while (S<N and v[S]<=x)
{S++;
if (v[S]>=x)
break;
}
fout<<S<<endl;
}
M=M-1;
}
return 0;
}
