-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoall.sh
executable file
·80 lines (64 loc) · 2.34 KB
/
doall.sh
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env zsh
# https://stackoverflow.com/a/19648328
ulimit -s unlimited
set -o errexit
if [[ "$#" != 1 ]]; then
echo "Usage: $0 CONTEST_NAME"
exit 1
fi
contest_name=$1
if [[ ! -d "$contest_name" ]]; then
echo "Contest '$contest_name' does not exists."
exit 1
fi
cd $contest_name
RELEASE='release'
mkdir -p $RELEASE
STATEMENT=$RELEASE/statement.md
echo '' > $STATEMENT
problem_count=64
for problem in $(cat PROBLEMS); do
problem_count=$(($problem_count + 1))
code=$(echo $problem_count | awk '{printf("%c", $1)}')
(cd $problem && rake -m)
problem_release=$RELEASE/$code
mkdir -p $problem_release
cp $problem/solution.{cc,cpp,py} $problem_release/ 2>/dev/null || true
cp $problem/slow.{cc,cpp} $problem_release/ 2>/dev/null || true
cp $problem/check.{cc,cpp} $problem_release/ 2>/dev/null || true
cp -r $problem/samples $problem_release
if grep packed $problem/Rakefile; then
cp -r $problem/tests/test.{in,out} $problem_release/
else
cp -r $problem/tests $problem_release
fi
if test -f $problem/statement.cn.md; then
cat $problem/statement.cn.md >> $STATEMENT
{
printf "\n## 样例输入\n\`\`\`\n"
cat $problem/samples/???
printf "\`\`\`\n\n## 样例输出\n\`\`\`\n"
cat $problem/samples/???.a
printf "\`\`\`\n\n"
} | python -c "import sys; sys.stdout.write(open('$STATEMENT').read().replace('<!--SAMPLES-->', sys.stdin.read()))" > $STATEMENT.new
else
cat $problem/statement.md >> $STATEMENT
{
printf "\n## Sample Input\n\`\`\`\n"
cat $problem/samples/???
printf "\`\`\`\n\n## Sample Output\n\`\`\`\n"
cat $problem/samples/???.a
printf "\`\`\`\n\n"
} | python -c "import sys; sys.stdout.write(open('$STATEMENT').read().replace('<!--SAMPLES-->', sys.stdin.read()))" > $STATEMENT.new
fi
mv $STATEMENT.new $STATEMENT
printf "\n\\\newpage\n\n" >> $STATEMENT
done
if [[ `uname -s` == "Darwin" ]]; then
font='Hiragino Sans GB'
else
font='Source Han Sans CN'
fi
pandoc $STATEMENT --latex-engine=xelatex -V CJKmainfont="$font" --template=../template.tex -o"$RELEASE/statement.pdf" \
|| pandoc $STATEMENT --pdf-engine=xelatex -V CJKmainfont="$font" --template=../template.tex -o"$RELEASE/statement.pdf"
cd ..