Import LeetCode problems with usaco new <link> / usaco daily
Test and publish the site / test (push) Successful in 35s
Test and publish the site / publish (push) Successful in 29s

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]>
This commit is contained in:
2026-10-19 21:12:16 +01:00
co-authored by Claude Opus 5.5
parent 995b44a57a
commit e821df15f4
9 changed files with 813 additions and 9 deletions
+10 -2
View File
@@ -6,12 +6,20 @@ io="$(detect_io "$dir" || true)"
io="${io:-$name}"
if [[ "${2:-}" != -y ]]; then
echo "This resets ${dir#$ROOT/} to a fresh template:"
echo " main.cpp -> re-created from template (old one saved as main.cpp.bak)"
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"
fresh_main "$dir" "$io"
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)"