usaco new <leetcode-link> (alias: from) and usaco daily fetch a problem from LeetCode's GraphQL API and write problem.md, main.cpp (template header + LeetCode's C++ starter), a generated driver.h that runs the solution on LeetCode-format input, and the examples as tests with the expected outputs from the statement. leetcode.h holds ListNode/TreeNode and the parse/print helpers; everything local sits behind #ifdef LOCAL so main.cpp stays submittable. reset re-fetches the starter code for LeetCode problems, the REPL's new selects the imported problem, and usaco.zsh turns off globbing so a pasted ?envType=... link works unquoted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
26 lines
1.0 KiB
Bash
26 lines
1.0 KiB
Bash
# usaco reset/rm/delete/template/tpl <name> [-y]
|
|
[[ $# -ge 1 ]] || usage
|
|
dir="$(find_problem "$1")"
|
|
name="$(basename "$dir")"
|
|
io="$(detect_io "$dir" || true)"
|
|
io="${io:-$name}"
|
|
if [[ "${2:-}" != -y ]]; then
|
|
echo "This resets ${dir#$ROOT/} to a fresh template:"
|
|
if [[ -f "$dir/driver.h" ]]; then
|
|
echo " main.cpp -> LeetCode's starter code again (old one saved as main.cpp.bak)"
|
|
else
|
|
echo " main.cpp -> re-created from template (old one saved as main.cpp.bak)"
|
|
fi
|
|
echo " removes compiled binary and $io.out (tests/ and $io.in are kept)"
|
|
read -r -p "Reset '$name'? [y/N] " ans
|
|
[[ "$ans" == y || "$ans" == Y ]] || { echo "Aborted."; exit 1; }
|
|
fi
|
|
[[ -f "$dir/main.cpp" ]] && cp "$dir/main.cpp" "$dir/main.cpp.bak"
|
|
if [[ -f "$dir/driver.h" ]]; then # a LeetCode import: re-fetch its starter code
|
|
python3 -I "$ROOT/lib/leetcode.py" "$ROOT" "$dir" --main-only >/dev/null || exit 1
|
|
else
|
|
fresh_main "$dir" "$io"
|
|
fi
|
|
rm -f "$dir/main" "$dir/a.out" "$dir/$io.out"
|
|
echo "Reset $name (old solution in main.cpp.bak)"
|