跳到正文

算法·理论

bash 一键测样例 + 对拍

SJZ2010约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年7月20日
篇幅
约 1 分钟

版本

  1. v1当前

一件测样例:

代码
# $1: Problem name
# $2: Whether use sanitizer ot not
# $3: first sample's id
# $4: last sample's id

ulimit -s 512000
if [ $2 == 1 ]; then
  g++ -o $1 $1.cpp -std=c++14 -O2 -Wall -fsanitize=address,undefined || exit
else
  g++ -o $1 $1.cpp -std=c++14 -O2 -static || exit
fi

echo -e "Compiled successfully\n"

for i in $(seq $3 $4); do
  cp $1$i.in $1.in
  \time -f $1$i": %es %MKB" ./$1 || exit
  diff -Zq $1.out $1$i.ans
done

对拍 in bash

代码
cnt=1
while true; do
  ./$1_gen
  cp $1_good.in $1.in 
  ./$1 || exit
  ./$1_good || exit
  if diff -Zq $1.out $1_good.out; then
    echo "$((cnt++)) AC"
  else
    echo "$cnt WA"
    exit
  fi
done
原文