Cod sursa(job #2750804)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 13 mai 2021 12:09:55
Problema Cbinteractiv Scor Ascuns
Compilator cpp-64 Status done
Runda Marime 0.41 kb
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n; cin >> n;

    int guess = 0;
    for(int step = (1 << 30); step > 0 ; step >>= 1)
    {
        int ng = guess + step;
        if(ng <= n) {
            cout << "? " << ng << endl;

            char ans; cin >> ans;
            if(ans == '0')
                guess = ng;
        }
    }

    cout << "! " << guess + 1 << endl;
    return 0;
}