033 · Princeton COS 217 A1 — Decomment
| 项目 | 内容 |
|---|---|
| 学校 | Princeton University |
| 课程 | COS 217 Introduction to Programming Systems |
| 方向 | C / 有限状态机与词法边界 |
| 语言 | C |
| 难度 | 入门 / Introductory |
| 上游仓库 | https://github.com/COS217/Decomment |
为什么收录
这道题只有 60 行有效代码,却是整门课最锋利的边界训练:注释不能出现在字符串里、转义的反斜杠会翻转引号的含义、多行注释必须保留行号、文件在注释中途结束要精确报出起始行。官方 starter 自带 74 个输入文件,把这套组合爆炸拆成可枚举的用例。
Sixty lines of code, but the sharpest boundary training in the course: comment markers inside literals, escapes that flip what a quote means, line numbers preserved across multi-line comments, and an exact line report when the file ends mid-comment. The starter ships 74 input files that enumerate the combinations.
实测结果
- 规格表格中的例子全部逐字节复现:38/38 金标准通过
- 官方 74 个输入文件与独立 Python oracle 交叉验证:74/74 一致
- 实现过程中修掉一个真实缺陷:文件以孤立
/结尾时该字符被吞掉(EOF 时状态仍停在“待定斜杠”)