Cod sursa(job #2790194)

Utilizator popashtefan10Popa Stefan popashtefan10 Data 28 octombrie 2021 16:26:14
Problema Cbinteractiv Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <cstdio>

using namespace std;

int cb(int st, int dr) {
  int last = -1;

  while(st <= dr) {
    int mij = (st + dr) / 2;
    printf("? %d\n", mij);
    fflush(stdout);

    int cmp;
    scanf("%d", &cmp);
    if(cmp == -1)
      return -1;
    if(cmp == 0)
      st = mij + 1;
    else {
      last = mij;
      dr = mij - 1;
    }
  }

  return last;
}

int main() {

  int n;
  scanf("%d", &n);

  printf("! %d\n", cb(1, n));
  fflush(stdout);

  return 0;
}