Cod sursa(job #3146539)

Utilizator SpiderManSimoiu Robert SpiderMan Data 21 august 2023 15:17:50
Problema Cbinteractiv Scor 0
Compilator java Status done
Runda Arhiva educationala Marime 0.71 kb
package main;

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        PrintWriter output = new PrintWriter(System.out, true);
        int left = 1;
        int right = input.nextInt();
        while (left < right) {
            int half = (left + right) / 2;
            output.printf("? %d%n", half);
            switch (input.nextInt()) {
                case 0 -> left = half + 1;
                case 1 -> right = half;
                default -> {
                    return;
                }
            }
        }
        output.printf("! %d%n".formatted(left));
        output.flush();
    }
}