Cod sursa(job #264567)
| Utilizator | Data | 22 februarie 2009 12:53:36 | |
|---|---|---|---|
| Problema | Cautare binara | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream.h>
#include <iostream.h>
fstream f("cautbin.in",ios::in);
fstream g("cautbin.out",ios::out);
long a[100001],i,N,j;
int ok;
unsigned m;
int main()
{
f>>N;
ok=0;
i=1; j=N;
while ((i<=j) && (ok==0))
{
m=(i+j)/2;
if a[m]=x ok=1;
else {
if a[m]>x j=m-1
else i=i+1;
};
};
if (ok==1) g<<m<<"\n";
else g<<"-1\n";
f.close();
g.close();
return 0;
}