-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcj.sh
More file actions
executable file
·58 lines (51 loc) · 1.3 KB
/
cj.sh
File metadata and controls
executable file
·58 lines (51 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# THIS SCRIPT IS FOR GOOGLE CODE JAM TESTING
# SUPPORTS CPP and PYTHON
# Extract file name
STRIN="$1"
FNAME="${STRIN%.*}"
EXT="${STRIN#*.}"
N="${STRIN:0:2}"
NAME="${FNAME:2}"
filePathFull="$(find . -name $STRIN -exec dirname {} \;)"
foundPathCount=$(find . -name $STRIN -exec dirname {} \; | wc -l)
filePath="${filePathFull:2}"
if [ $foundPathCount -eq 0 ];
then
echo "Error: No files named $STRIN have been found."
exit 1
elif [ $foundPathCount -gt 1 ];
then
echo "Error: Multiple files of $STRIN have been found. Locations are:"
echo "$filePathFull"
exit 1
fi
# Compile script if extension is cpp
if [ "$EXT" == "cpp" ]
then
g++ "${filePath}/${STRIN}" -std=c++14 -pthread -O3 -o "${filePath}/${FNAME}.o"
echo "completed c++ compiling!"
fi
# Run input text
INTXT="${N}0in.txt"
OUTTXT="${N}0out.txt"
# Create input file (if not present)
if [ -f "${filePath}/${INTXT}" ]
then
A="A"
else
echo "Input file generated. Please re-run with input data."
touch "${filePath}/${INTXT}"
return
fi
# run script
start=$(date +%s)
if [ $EXT == "cpp" ]
then
"./${filePath}/${FNAME}.o" < "${filePath}/$INTXT" > "${filePath}/$OUTTXT"
else
python3 "${filePath}/${STRIN}" < "${filePath}/$INTXT" > "${filePath}/$OUTTXT"
fi
end=$(date +%s)
runtime=$(python3 -c "print(${end} - ${start})")
echo "Runtime: $runtime second(s)."