Cod sursa(job #3302646)
| Utilizator | Data | 9 iulie 2025 18:05:51 | |
|---|---|---|---|
| Problema | Cautare binara | Scor | 40 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 1.01 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("cautbin.in");
ofstream fout ("cautbin.out");
int v[100000];
int main()
{
int n;
fin>>n;
for (int i=0;i<n;i++){
fin>>v[i];
}
int m;
fin>>m;
int cb,x;
for (int i=0;i<m;i++){
fin>>cb>>x;
if (cb==0){
int poz=-1;
for (int j=0;j<n;j++){
if (v[j]==x){
poz=j+1;
}
}
fout<<poz<<endl;
}
else if (cb==1){
int poz=1;
for (int j=0;j<n;j++){
if (v[j]<=x){
poz=j+1;
}
}
fout<<poz<<endl;
}
else {
int poz=1;
for (int j=0;j<=n;j++){
if (v[j]>=x){
poz=j+1;
break;
}
}
fout<<poz<<endl;
}
}
return 0;
}
