diff --git a/package.json b/package.json index 6071104..d9df2a8 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "file-size": "^1.0.0", "fs-extra": "^2.1.2", "gravatar": "^1.5.2", + "js-yaml": "^3.9.0", "moemark-renderer": "^1.2.6", "moment": "^2.15.0", "multer": "^1.2.0", diff --git a/utility.js b/utility.js index e754f1b..a1534ed 100644 --- a/utility.js +++ b/utility.js @@ -209,7 +209,7 @@ module.exports = { let list = await (await fs.readdirAsync(dir)).filterAsync(async x => await syzoj.utils.isFile(path.join(dir, x))); let res = []; - if (!list.includes('data_rule.txt')) { + if (!list.includes('data.yml')) { res[0] = {}; res[0].cases = []; for (let file of list) { @@ -247,52 +247,37 @@ module.exports = { return getLastInteger(a.input) - getLastInteger(b.input); }); + + res.spj = list.some(s => s.startsWith('spj_')); } else { - let lines = (await fs.readFileAsync(path.join(dir, 'data_rule.txt'))).toString().split('\r').join('').split('\n').filter(x => x.length !== 0); + let config = require('js-yaml').load((await fs.readFileAsync(dir + '/data.yml'))); - let input, output, answer; - if (submitAnswer) { - if (lines.length < 4) throw '无效的数据配置文件(data_rule.txt)。'; - input = lines[lines.length - 3]; - output = lines[lines.length - 2]; - answer = lines[lines.length - 1]; - } else { - if (lines.length < 3) throw '无效的数据配置文件(data_rule.txt)。'; - input = lines[lines.length - 2]; - output = lines[lines.length - 1]; - } + let input = config.inputFile, output = config.answerFile, answer = config.userOutput; - for (let s = 0; s < lines.length - (submitAnswer ? 3 : 2); ++s) { - res[s] = {}; - res[s].cases = []; - let numbers = lines[s].split(' ').filter(x => x); - if (numbers[0].includes(':')) { - let tokens = numbers[0].split(':'); - res[s].type = tokens[0] || 'sum'; - res[s].score = parseFloat(tokens[1]) || (100 / (lines.length - 2)); - numbers.shift(); - } else { - res[s].type = 'sum'; - res[s].score = 100; - } - for (let i of numbers) { - let testcase = { - input: input.replace('#', i), - output: output.replace('#', i) - }; + res = config.subtasks.map(st => ({ + score: st.score, + type: st.type, + cases: st.cases.map(c => { + function getFileName(template, id) { + let s = template.split('#').join(String(id)); + if (!list.includes(s)) throw `找不到文件 ${s}`; + return s; + } - if (submitAnswer) testcase.answer = answer.replace('#', i); + let o = {}; + if (input) o.input = getFileName(input, c); + if (output) o.output = getFileName(output, c); + if (answer) o.answer = getFileName(answer, c); - if (testcase.input !== '-' && !list.includes(testcase.input)) throw `找不到文件 ${testcase.input}`; - if (testcase.output !== '-' && !list.includes(testcase.output)) throw `找不到文件 ${testcase.output}`; - res[s].cases.push(testcase); - } - } + return o; + }) + })); res = res.filter(x => x.cases && x.cases.length !== 0); + + res.spj = !!config.specialJudge; } - res.spj = list.some(s => s.startsWith('spj_')); return res; } catch (e) { console.log(e); diff --git a/views/problem_testcases.ejs b/views/problem_testcases.ejs index 4abc867..a85959d 100644 --- a/views/problem_testcases.ejs +++ b/views/problem_testcases.ejs @@ -12,6 +12,8 @@ let subtaskType = { %> <% if (testcases.spj) { %>

评测方式:Special Judge

+ <% } else if (problem.type === 'interaction') { %> +

评测方式:交互

<% } else { %>

评测方式:文本比较

<% } %> @@ -33,12 +35,12 @@ let subtaskType = { <%= testcase.input || '-' %> <%= testcase.output || '-' %> - <%= testcase.answer %> + <%= testcase.answer || '-' %> <% } else { %> - <%= testcase.input %> - <%= testcase.output %> + <%= testcase.input || '-' %> + <%= testcase.output || '-' %> <% } %> <% } %> diff --git a/views/submission_content.ejs b/views/submission_content.ejs index 47bac1d..24b1c3c 100644 --- a/views/submission_content.ejs +++ b/views/submission_content.ejs @@ -147,7 +147,7 @@ else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);

系统调试信息

<%= judge.result.message %>
<% } else if (judge.result.spj_compiler_output) { %> -

Special Judge 编译信息

+

<%= judge.problem.type === 'interaction' ? '交互程序' : 'Special Judge ' %>编译信息

<%- syzoj.utils.ansiToHTML(judge.result.spj_compiler_output) %>
<% } else if (judge.allowedSeeCase && judge.result.subtasks && (judge.result.subtasks.length !== 1 || judge.result.subtasks[0].case_num)) { %>
@@ -189,12 +189,14 @@ else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);

输入文件<% if (testcase.input_file_name) { %>(<%= testcase.input_file_name %>)<% } %>

<%= testcase.input %>
- 输出文件<% if (testcase.output_file_name) { %>(<%= testcase.output_file_name %>)<% } %> -
<%= testcase.answer %>
- 选手输出 -
<%= testcase.user_out %>
+ <% if (judge.problem.type !== 'interaction') { %> + 输出文件<% if (testcase.output_file_name) { %>(<%= testcase.output_file_name %>)<% } %> +
<%= testcase.answer %>
+ 选手输出 +
<%= testcase.user_out %>
+ <% } %> <% if (testcase.spj_message) { %> - Special Judge 信息 + <%= judge.problem.type === 'interaction' ? '交互程序' : 'Special Judge ' %>信息
<%= testcase.spj_message %>
<% } %> <% if (testcase.user_err) { %>