Cod sursa(job #3234850)
Utilizator | Data | 12 iunie 2024 01:08:43 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int left = 1, right = N;
while (left <= right) {
int mid = left + (right - left) / 2;
cout << "? " << mid << endl;
cout.flush();
int response;
cin >> response;
if (response == 0) {
cout << "! " << mid << endl;
cout.flush();
break;
} else if (response == 1) {
left = mid + 1;
} else if (response == -1) {
right = mid - 1;
}
}
return 0;
}