# usaco reset/rm/delete/template/tpl [cpp|rust] [-y] [[ $# -ge 1 ]] || usage dir="$(find_problem "$1")"; shift name="$(basename "$dir")" yes=""; lang="" for a in "$@"; do if [[ "$a" == -y ]]; then yes=1; else lang="$(normalize_lang "$a")" || exit 1; fi done lang="${lang:-$(lang_of "$dir" 2>/dev/null || default_lang)}" leet=""; [[ -f "$dir/driver.h" ]] && leet=1 if [[ -n "$leet" && "$lang" != cpp ]]; then echo "Error: $name is a LeetCode import, and those are C++ only" >&2; exit 1 fi io="$(detect_io "$dir" || true)" io="${io:-$name}" old="$(main_file "$dir" 2>/dev/null || true)" src="$(src_name "$lang")" if [[ -z "$yes" ]]; then echo "This resets ${dir#$ROOT/} to a fresh $lang template:" if [[ -n "$leet" ]]; then echo " $src -> LeetCode's starter code again (old one saved as $src.bak)" else echo " $src -> re-created from template (old one saved as $(basename "${old:-$src}").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 [[ -n "$old" && -f "$old" ]] && cp "$old" "$old.bak" # switching language: drop the old source so lang_of stays unambiguous [[ -n "$old" && "$(basename "$old")" != "$src" ]] && rm -f "$old" if [[ -n "$leet" ]]; 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" "$lang" fi [[ "$lang" == rust || "$old" == *.rs ]] && sync_cargo_manifest >/dev/null rm -f "$dir/main" "$dir/a.out" "$dir/$io.out" echo "Reset $name (old solution in $(basename "${old:-$src}").bak)"