#!/bin/bash
rm -f a.out temp.ans *.class

if [[ $1 == *.cpp ]]
then
    echo "Compiling cpp $1"
    g++ -g -O2 -std=gnu++17 -static $1
    EXEC=./a.out
elif [[ $1 == *.cc ]]
then
    echo "Compiling cc $1"
    g++ -g -O2 -std=gnu++17 -static $1
    EXEC=./a.out
elif [[ $1 == *.py ]]
then
    echo "It's Python"
    EXEC="pypy3 $1"
elif [[ $1 == *.c ]]
then
    echo "It's C"
    gcc -g -O2 -std=gnu11 -static $1 -lm
    EXEC=./a.out
elif [[ $1 == *.java ]]
then
    echo "It's Java!"
	javac $1
	EXEC="java $1"
else
    echo "Don't know what this is!"
fi

for f in $2/*.in
do
    echo "Judging $f"
    time $EXEC < $f > "${f%.*}.ans"
#    time $EXEC < $f
done 

rm -f a.out temp.ans *.class
