fix(提交): C 代码编译不过时,提交前的自动格式化把出错的几行并成一行,学生认不出自己的代码
Deploy / deploy (push) Canceled after 0s

clang-format 不认中文分号、缺了分号的语句,会把它和下一行并起来(int n; 和 scanf 成了
一行),报错的行号也对不上学生记得的位置。现在 C / C++ 格式化之前先套上题目模板、在
判题机上编一次,编不过就原样返回、不格式化,代码照常提交、照常判成编译错误。

api 容器里没有 gcc,判题机的编译器和参数本来就是判的标准,所以借它编。这一下不进判题
队列、不建提交记录;判题机连不上时照旧格式化。代价是每次交 C 多一次编译,零点几秒。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-09-30 11:29:37 +08:00
1 parent fa092d334c
commit c2ef55b10b
5 files changed
+51 -3

No files matched your search

+21
View File
@@ -112,6 +112,27 @@ export async function postJudge(
return response
}
/**
* 这份代码在判题机上编不编得过。给提交前的自动格式化用:clang-format 碰上编译不过的
* C 代码会把行并起来(`int n;` 和下一行、少了分号的两行),学生回头看到的就不是自己
* 写的代码了,报错的行号也对不上他记得的位置。api 容器里没有 gcc,而判题机的编译器、
* 编译参数本来就是判的标准,所以借它编一次。
*
* 判题机只有 /judge 一个入口,得带一组测试点:给一组空输入,跑的那一下限 1 秒。
* 判题机连不上、超时,一律当编得过 —— 那就和原来一样照常格式化。
*/
export async function compileFails(language: string, source: string) {
try {
const response = await postJudge(language, source, 1000, 256, [{ input: "", output: "" }], {
signal: AbortSignal.timeout(8000),
})
const body = (await response.json()) as JudgeResponse
return body.err === "CompileError"
} catch {
return false
}
}
async function requestJudge(
language: string,
code: string,