跳到正文

科技·工程

对拍Linux实现

Rt__约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年11月28日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 2 分钟

版本

  1. v1当前

准备

- 正确代码 / 待拍代码 各一份(apple_bl.cpp / apple.cpp)

- 数据生成器(make.cpp)

使用 C++ 生成

- 对拍脚本(DP.sh)

解释如下:

Bash
g++ apple_bl.cpp -o apple_bl
g++ apple.cpp -o apple
g++ make.cpp -o make

# 编译生成可执行程序

while true 
do
    ./make > 1.in
    ./apple_bl < 1.in > right.out
    ./apple < 1.in > wrong.out

    # 生成数据并且产生输出

    diff -Z right.out wrong.out
    if [ $? -ne 0 ]; then
        echo "" # 换行用
        cat 1.in
        echo ""
        break
    fi

    # 比较,不同则输出产生不同的输入输出
done

$?是上一个语句产生的返回值(上面就是diff函数返回的,不同:1 / 相同:0)

-ne相当于!=

- 获取可执行权限

chmod +x DP.sh

- 运行

在终端(Linux 终端或 VScode终端)输入./DP.sh运行。

- 效果

或者直接在1.in和right.out / wrong.out查看。

原文