-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpp_competitive_template.sh
More file actions
executable file
·115 lines (103 loc) · 2.22 KB
/
cpp_competitive_template.sh
File metadata and controls
executable file
·115 lines (103 loc) · 2.22 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
main() {
# no input
if (($# < 1)); then
print_usage
exit 1
fi
# get flags
contest_flag=0
specify_flag=0
num_problems=0
while getopts "c:s:h" flag; do
case $flag in
c)
num_problems=$OPTARG
contest_flag=1 ;;
s)
problem_names=$OPTARG
specify_flag=1 ;;
h)
print_usage
exit ;;
esac
done
# num_problems not integer
if ! [[ "$num_problems" =~ ^[0-9]+$ ]]; then
echo "Error: expected integer"
print_usage
exit 1
fi
if (($contest_flag > 0)); then
echo "creating contest problems..."
problems=("A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T")
for ((i=0;i<$num_problems;i++));
do
echo "creating file ${problems[$i]}.cpp..."
create_file ${problems[$i]}
done
elif (($specify_flag > 0)) ;then
names=$(echo $problem_names | tr "," " ")
for name in $names
do
echo "creating file $name.cpp..."
create_file $name
done
else
filename="$1"
echo "creating file $filename.cpp..."
create_file $filename
fi
create_io_files
echo "Done!"
}
create_file() {
local code=(
"#include <bits/stdc++.h>"
"using namespace std;"
"#define DEBUG(x) cout << #x << \" >>>> \" << x << endl"
"#define MID(l, r) (l + (r - l) / 2)"
"#define CEILDIVISION(x, y) ((x + y - 1) / y)"
"#define INF (long long)1e18"
"#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);"
"using ll = long long;"
"const int MOD = 1e9 + 7; // 10^9 + 7"
""
"int main() {"
" FASTIO;"
" ll t;"
" cin >> t;"
" "
" while(t--){"
""
" "
""
""
" }"
" "
" return 0;"
"}"
)
for line in "${code[@]}"; do
echo "$line"
done > "$1.cpp"
}
create_io_files() {
input=in.txt
output=out.txt
if ! test -f "$input"; then
echo "creating $input..."
touch "in.txt"
fi
if ! test -f "$output"; then
echo "creating $output..."
touch "out.txt"
fi
}
print_usage() {
echo "Usage:
create single file: cpp_competitive_template.sh <filename>
start a contest: -c <num_problems>
specify file names: -s <file1>,<file2>,..."
}
main "$@"; exit