제출 #774979

#제출 시각아이디문제언어결과실행 시간메모리
774979hgmhcGuess the number (BOI20_guess)C++17
100 / 100
1 ms292 KiB
#include <bits/stdc++.h>
using namespace std;

bool f(int x) {
    printf("? %d\n", x);
    fflush(stdout);
    int q; scanf("%d", &q);
    if (q == 0) {
        printf("= %d\n", x);
        fflush(stdout);
        exit(0);
    }
    else if (q < 0) return true;
    else return false;
}

int main() {
    int n; scanf("%d", &n);
    int a = 1, b = n;
    while (a <= b) {
        int m = (a+b)/2;
        if (f(m)) a = m+1;
        else b = m-1;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

Guess.cpp: In function 'bool f(int)':
Guess.cpp:7:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     int q; scanf("%d", &q);
      |            ~~~~~^~~~~~~~~~
Guess.cpp: In function 'int main()':
Guess.cpp:18:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     int n; scanf("%d", &n);
      |            ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...