文件
csp/remote_patch_cpp_basic_20.py
cryptocommuniums-afk 2b6def2560 feat: print includes answer only after unlocking solutions
- If solutions already unlocked (full mode), print button shows '打印题目+答案'
- If not unlocked, print button shows '打印题目' (problem only)
- No longer forces unlock when printing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-16 21:19:57 +08:00

44 行
1016 B
Python

#!/usr/bin/env python3
from __future__ import annotations
import argparse
from pathlib import Path
def main():
ap = argparse.ArgumentParser()
ap.add_argument('--file', required=True)
ap.add_argument('--items', required=True)
args = ap.parse_args()
p = Path(args.file)
items = Path(args.items).read_text(encoding='utf-8')
s = p.read_text(encoding='utf-8')
marker = 'const CourseItem items[] = {'
i = s.find(marker)
if i < 0:
raise SystemExit(f'cannot find marker: {marker}')
j = s.find('};', i)
if j < 0:
raise SystemExit('cannot find end marker "};" after items start')
before = s[:i]
after = s[j+2:]
out = before + items + after
if out == s:
print('no change')
return
backup = p.with_suffix(p.suffix + '.bak_cppbasic20')
backup.write_text(s, encoding='utf-8')
p.write_text(out, encoding='utf-8')
print('patched', str(p))
print('backup', str(backup))
if __name__ == '__main__':
main()