跳到正文

个人记录

女生自用99新(?)基于shell的对拍脚本

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

文章信息

发布
2023年11月16日
收录
2025年12月12日
更新
2026年11月19日
篇幅
约 2 分钟
获赞
1

版本

  1. v1当前
Bash
#!/bin/bash

while true; do
    ./gen > in
    ./bruteforce < in > ans
    time (./solution < in > out)
    ret=$?
    if [ $ret -ne 0 ]; then
        echo "Runtime Error with return value $ret"
        break
    fi
    diff -Z out ans
    if [ $? -ne 0 ]; then
        echo "Wrong Answer"
        break
    fi
done

文件读写改一下就完了

带(简单)时限管理和出错醒目提醒

Bash
#!/bin/bash
while true; do
    ./gen > in
    ./bruteforce < in > ans

    time (timeout 1 ./solution < in > out)
    ret=$?

    if [ $ret -ne 0 ]; then
        if [ $ret -eq 124 ]; then
            notify-send "Time Limit Exceeded"
            echo "Time Limit Exceeded"
        else
            notify-send "Runtime Error with return value $ret"
            echo "Runtime Error with return value $ret"
        fi 
        break
    fi

    diff -Z out ans

    if [ $? -ne 0 ]; then
        notify-send "Wrong Answer"
        echo "Wrong Answer"
        break
    fi
done
原文
存档评论7 条抓取于