Cod sursa(job #2438487)
| Utilizator | Data | 12 iulie 2019 16:52:22 | |
|---|---|---|---|
| Problema | Cautare binara | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.9 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,m,val,c,a[100001];
bool ok=true;
int main()
{
f>>n;
for(int i=1; i<=n; i++)
f>>a[i];
f>>m;
for(int i=1; i<=m; i++)
{
f>>c>>val;
if(c==0)
{
for(int j=n; j&&ok; j--)
if(val==a[j])
{
ok=false;
g<<j<<'\n';
}
if(ok)
g<<-1;
ok=1;
}
else if(c==1)
{
for(int j=n; j&&ok; j--)
if(!(a[j]>val))
g<<j<<'\n',ok=0;
ok=1;
}
else
{
for(int j=1;j<=n&&ok;j++)
if(a[j]>=val)
g<<j<<'\n',ok=0;
ok=1;
}
}
return 0;
}
