Online Practice (在线练习)
Write Python in the browser and run it against the repository’s own reference answers. No account, no server: the Python runtime is Pyodide in a WebAssembly sandbox, the expected values in problems.json were produced by executing the checked-in solutions, and your code is saved in this browser’s localStorage.
在浏览器里写 Python,直接拿仓库里参考实现的真实输出来判题。不需要账号、没有后端:Python 跑在 Pyodide 的 WebAssembly 沙箱里,期望值由
scripts/gen-oj-problems.py执行真实 solution 生成,代码保存在本机浏览器。用「导出进度」可以把代码搬到另一台机器。
Works offline after the first load? No — Pyodide is fetched from a CDN once (~10 MB) and then cached by the browser. Everything else is served from this site.
载入中…
初始化…判题规则 / How grading works (0.1)
每题给起始代码和 6 个用例。评测时你的代码在一个干净的命名空间里执行,每个用例独立运行——一个用例里的异常不会影响下一个。
对每个用例,平台比较 repr(你的返回值) 与 repr(参考实现的返回值)。这不是字符串近似匹配:类型、顺序、元组与列表的差别都会被算作失败。失败时显示期望值、实际值和 Python 抛出的异常。
Six cases per problem. Each runs in a fresh namespace, so an exception in one cannot contaminate the next. The comparison is on
repr()— type and order matter. A failed case shows what was expected, what came back, and the traceback.
边界与诚实 / Limits (0.2)
- 只有 Python。 21 道题的参考实现是 Python;其余 13 道(C / C++ / Java / Go)需要编译器,浏览器内执行不现实。它们仍可在书站查看完整解析。
- 不能跨设备自动同步。
localStorage属于当前浏览器。导出 JSON 再导入是现阶段的同步方式;要做账号系统必须有后端,而 GitHub Pages 只能托管静态文件。 - 没有真正的超时保护。 死循环会卡住当前标签页,关掉页面重开即可——你的代码只能伤到自己这个标签。
- 期望值不是教授给的。 它们来自我们自己的参考实现(详见各题的七章解析),所以对规格的理解如果有偏差,这里也会一样偏差。
Only Python; no automatic cross-device sync; an infinite loop freezes only your own tab; expected values come from our reference solutions, not from the course.