Import LeetCode problems with usaco new <link> / usaco daily
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:
@@ -8,6 +8,9 @@
|
||||
USACO_ROOT="${0:A:h}"
|
||||
|
||||
usaco() { "$USACO_ROOT/usaco" "$@"; }
|
||||
# no globbing on usaco's arguments, so a pasted link like .../two-sum/?envType=x
|
||||
# isn't a "no matches found" error (nothing usaco takes is a glob anyway)
|
||||
alias usaco='noglob usaco'
|
||||
|
||||
ucd() {
|
||||
local dir
|
||||
@@ -29,6 +32,8 @@ _usaco() {
|
||||
'repl:interactive mode (REPL with a current problem)'
|
||||
'new:create a problem from template'
|
||||
'n:create a problem from template'
|
||||
'from:import a LeetCode problem from its link'
|
||||
"daily:import today's LeetCode daily question"
|
||||
'run:build and run main.cpp'
|
||||
'r:build and run main.cpp'
|
||||
'build:build main.cpp'
|
||||
@@ -70,7 +75,7 @@ _usaco() {
|
||||
_describe 'command' cmds
|
||||
elif (( CURRENT == 3 )); then
|
||||
case "$words[2]" in
|
||||
i|interactive|repl|new|n|list|l|ls|stats|st|clean|sync|sy) ;; # no problem-name argument
|
||||
i|interactive|repl|new|n|from|daily|list|l|ls|stats|st|clean|sync|sy) ;; # no problem-name argument
|
||||
test|t)
|
||||
local -a subs
|
||||
subs=('create:save a new test case' 'add:save a new test case' 'new:save a new test case')
|
||||
|
||||
Reference in New Issue
Block a user