Skip to content

Instantly share code, notes, and snippets.

@rana-ahmed
Created September 20, 2015 13:38
Show Gist options
  • Select an option

  • Save rana-ahmed/d0999ef3f753fde2dbab to your computer and use it in GitHub Desktop.

Select an option

Save rana-ahmed/d0999ef3f753fde2dbab to your computer and use it in GitHub Desktop.
A simple bash script to compile, run and compare result file to judge result file for C programming language
#!/bin/bash
#try to compile the file
gcc -lm main.c -o main
#if compile successful then go on
if [[ $? = 0 ]]; then
#try to run program with time limite
timeout 1s ./main < input.txt
RV=$?
#if program run within the time then write result into output.txt file
if [[ $RV = 0 ]]; then
./main < input.txt > output.txt
#compare judge output file and current output file
cmp -s answer.txt output.txt > /dev/null
#if two file is same then result yes
if [[ $? = 0 ]]; then
echo "yes" > result.txt
#if those are not same then result no
else
echo "no" > result.txt
fi
#if program can not run within the time then result TE
elif [[ $RV = 124 ]]; then
echo "TE" > result.txt
#it means there is run time error
else
echo "RE" > result.txt
fi
#we found compilation error
else
echo "CE" > result.txt
fi
@Wahmskouza
Copy link
Copy Markdown

Le résultat correct du match entre le Bayern Munich et le Borussia Dortmund

@Wahmskouza
Copy link
Copy Markdown

النتيجة الصحيحة للمباراة بين بايرن ميونخ وبوروسيا دورتموند

@Wahmskouza
Copy link
Copy Markdown

Le résultat correct du match entre le Bayern Munich et le Borussia Dortmund

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment