Cod sursa(job #2939352)
Utilizator | Data | 13 noiembrie 2022 16:06:05 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
using namespace std;
int n, x, st, dr, mid;
int main()
{
cin>>n;
st = 1;
dr = n;
while(st<=dr)
{
mid = (st+dr)/2;
cout<<"? "<<mid<<"\n";
cout.flush();
cin>>x;
if(x == 0)
{
st = mid + 1;
}
else if(x == 1)
{
dr = mid - 1;
}
else if(x == -1)
{
return 0;
}
}
cout<<"! "<<st;
cout.flush();
return 0;
}