From 7029af92549da7793e4874d516b5828bda240641 Mon Sep 17 00:00:00 2001 From: Himit_ZH <372347736@qq.com> Date: Tue, 18 Jan 2022 20:51:54 +0800 Subject: [PATCH] allowed no ouput file --- docs/docs/use/testcase.md | 2 +- .../hoj/controller/file/TestCaseController.java | 8 ++++---- .../service/problem/impl/ProblemServiceImpl.java | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/docs/docs/use/testcase.md b/docs/docs/use/testcase.md index ff36993a..5dd6d629 100644 --- a/docs/docs/use/testcase.md +++ b/docs/docs/use/testcase.md @@ -33,7 +33,7 @@ 然后压缩测试用例到一个zip中 :::danger -**注意:即使没有输入或者没有输出,也请提供对应的空输入(输出)文件,不要在这些文件外面套多一层文件夹,请直接压缩!!!** +**注意:不要在这些文件外面套多一层文件夹,请直接压缩!!!** ::: :::info diff --git a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/file/TestCaseController.java b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/file/TestCaseController.java index 2ed5c178..3cc42012 100644 --- a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/file/TestCaseController.java +++ b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/file/TestCaseController.java @@ -95,14 +95,14 @@ public class TestCaseController { // 进行数据对应检查,同时生成返回数据 List> problemCaseList = new LinkedList<>(); for (String key : inputData.keySet()) { - // 若有名字不对应,直接返回失败 + // 若有名字对应的out文件不存在的,直接生成对应的out文件 if (outputData.getOrDefault(key, null) == null) { - FileUtil.del(fileDir); - return CommonResult.errorResponse("请检查数据压缩包里面的in和out、ans文件是否一一对应!"); + FileWriter fileWriter = new FileWriter(fileDir + File.separator + key + ".out"); + fileWriter.write(""); } HashMap testcaseMap = new HashMap<>(); testcaseMap.put("input", inputData.get(key)); - testcaseMap.put("output", outputData.get(key)); + testcaseMap.put("output", key + ".out"); problemCaseList.add(testcaseMap); } diff --git a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/problem/impl/ProblemServiceImpl.java b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/problem/impl/ProblemServiceImpl.java index fa45e408..fc4b852f 100644 --- a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/problem/impl/ProblemServiceImpl.java +++ b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/problem/impl/ProblemServiceImpl.java @@ -272,6 +272,7 @@ public class ProblemServiceImpl extends ServiceImpl impl } else { newProblemCaseList.add(problemCase.setPid(pid)); } + if (problemCase.getScore() != null) { sumScore += problemCase.getScore(); } @@ -394,6 +395,10 @@ public class ProblemServiceImpl extends ServiceImpl impl if (problemCase.getScore() != null) { sumScore += problemCase.getScore(); } + if (StringUtils.isEmpty(problemCase.getOutput())) { + String filePreName = problemCase.getInput().split("\\.")[0]; + problemCase.setOutput(filePreName + ".out"); + } problemCase.setPid(pid); } // 设置oi总分数,根据每个测试点的加和 @@ -482,13 +487,16 @@ public class ProblemServiceImpl extends ServiceImpl impl FileReader inputFile = new FileReader(testCasesDir + File.separator + problemCase.getInput(), CharsetUtil.UTF_8); String input = inputFile.readString().replaceAll("\r\n", "\n"); - FileWriter fileWriter = new FileWriter(testCasesDir + File.separator + problemCase.getInput(), CharsetUtil.UTF_8); - fileWriter.write(input); + FileWriter inputFileWriter = new FileWriter(testCasesDir + File.separator + problemCase.getInput(), CharsetUtil.UTF_8); + inputFileWriter.write(input); // 读取输出文件 FileReader outputFile = new FileReader(testCasesDir + File.separator + problemCase.getOutput(), CharsetUtil.UTF_8); String output = outputFile.readString().replaceAll("\r\n", "\n"); + FileWriter outFileWriter = new FileWriter(testCasesDir + File.separator + problemCase.getOutput(), CharsetUtil.UTF_8); + outFileWriter.write(output); + // spj和interactive是根据特判程序输出判断结果,所以无需初始化测试数据 if (Constants.JudgeMode.DEFAULT.getMode().equals(mode)) { // 原数据MD5 @@ -706,12 +714,12 @@ public class ProblemServiceImpl extends ServiceImpl impl importProblemVo.setSamples(problemCaseList); if (!StringUtils.isEmpty(problem.getUserExtraFile())) { - HashMap userExtraFileMap = (HashMap) JSONUtil.toBean(problem.getUserExtraFile(), Map.class); + HashMap userExtraFileMap = (HashMap) JSONUtil.toBean(problem.getUserExtraFile(), Map.class); importProblemVo.setUserExtraFile(userExtraFileMap); } if (!StringUtils.isEmpty(problem.getJudgeExtraFile())) { - HashMap judgeExtraFileMap = (HashMap) JSONUtil.toBean(problem.getJudgeExtraFile(), Map.class); + HashMap judgeExtraFileMap = (HashMap) JSONUtil.toBean(problem.getJudgeExtraFile(), Map.class); importProblemVo.setUserExtraFile(judgeExtraFileMap); }