Created
April 26, 2021 13:28
-
-
Save haile01/b46e87a90d4c470d29a10c89dbcfda31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# To create workspace, run ./judge.sh --prepare <file_name>, it will create a main code file <file_name>_ans.cpp, a judger file <file_name>.cpp and a test generator file <file_name>_gen.cpp | |
# To start judging, run ./judge.sh <file_name> and sit back, enjoy ;) | |
if [[ $1 == "--prepare" ]]; then | |
echo -e "#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n\t// Main source code here\n}" > "./$2.cpp"; | |
echo -e "#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n\t// Bruteforce solution here\n}" > "./$2_ans.cpp"; | |
echo -e "#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main() {\n\t// Test generator here\n}" > "./$2_gen.cpp"; | |
else | |
echo "Judging $1.cpp" | |
if gcc "./$1.cpp" -lstdc++ -o sol; then | |
if gcc "./$1_ans.cpp" -lstdc++ -o ans; then | |
if gcc "./$1_gen.cpp" -lstdc++ -o gen; then | |
echo "Compile successful"; | |
echo "===Judging==="; | |
for (( i = 0; i < $2; i++)) | |
do | |
echo -e "=====\nJudging test $i"; | |
./gen > "./$1.inp"; | |
s=$(echo "($(date +"%s.%N") * 1000) / 1" | bc); | |
./sol < "./$1.inp" > "./$1.out"; | |
s=`expr $(echo "($(date +"%s.%N") * 1000) / 1" | bc) - $s`; | |
./ans < "./$1.inp" > "./$1.ans"; | |
if ! diff "./$1.out" "./$1.ans"; then | |
echo "SHIT SHIT SHIT"; | |
break; | |
fi | |
echo "Run successfully in $s ms"; | |
done; | |
rm -rf ./gen; | |
else | |
echo "[$1_gen.cpp] Compile error"; | |
fi; | |
rm -rf ./ans | |
else | |
echo "[$1_ans.cpp] Compile error"; | |
fi; | |
rm -rf ./sol | |
else | |
echo "[$1.cpp] Compile error"; | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment