From 432195eab75c11ada90b8287a65cc25f48237f4f Mon Sep 17 00:00:00 2001 From: Pisces000221 <1786762946@qq.com> Date: Mon, 31 Jul 2017 17:08:27 +0800 Subject: [PATCH] Fix automatic ordering for test cases --- utility.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/utility.js b/utility.js index 2331933..d690a2a 100644 --- a/utility.js +++ b/utility.js @@ -244,9 +244,14 @@ module.exports = { res[0].type = 'sum'; res[0].score = 100; + res[0].cases.forEach((e) => { e.key = (e.input.match(/\d+/g) || []).map((x) => parseInt(x)).concat(e.input); }); res[0].cases.sort((a, b) => { - let extractNumerals = (s) => (s.match(/\d+/g) || []).map((x) => parseInt(x)).concat(s); - return extractNumerals(a.input) < extractNumerals(b.input) ? -1 : +1; + for (let i = 0; i < Math.max(a.key.length, b.key.length); ++i) { + if (a.key[i] == undefined) return -1; + if (b.key[i] == undefined) return +1; + if (a.key[i] !== b.key[i]) return (a.key[i] < b.key[i] ? -1 : +1); + } + return 0; }); res.spj = list.some(s => s.startsWith('spj_'));