📜  交互式问题 - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:29.249000             🧑  作者: Mango

代码示例1
#include 
#include 

using namespace std;

int main() {
    int l = 1, r = 1000000;
    while (l != r) {
        int mid = (l + r + 1) / 2;
        printf("%d\n", mid);
        fflush(stdout);

        char response[3];
        scanf("%s", response);
        if (strcmp(response, "<") == 0)
            r = mid - 1;
        else
            l = mid;
    }

    printf("! %d\n", l);
    fflush(stdout);
}