来个 puzzle

· · 科技·工程

// judge.cpp

#include <cstdio>
#include <random>

typedef u_int32_t u32;

u32 guess(void);

__attribute__ ((__noinline__))
u32 sample() {
    return std::random_device()();
}

int main() {
    u32 x = sample();
    u32 y = guess();
    printf("%u <-> %u\n", x, y);
    return 0;
}

实现 guess.cpp,其中实现了 u32 guess(void) 函数,使得 printf 时两个数总是相同。

编译命令:

g++ judge.cpp guess.cpp -Werror -O2 -o judge