Created
September 20, 2015 13:38
-
-
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
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 | |
| #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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Le résultat correct du match entre le Bayern Munich et le Borussia Dortmund