mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
utils: subtask matcher: support uppercase
This commit is contained in:
1 file changed
+20
-32
@@ -236,7 +236,7 @@ export function sortFiles(files: Record<string, any>[] | string[], key = '_id')
|
|||||||
|
|
||||||
interface MatchRule {
|
interface MatchRule {
|
||||||
regex: RegExp;
|
regex: RegExp;
|
||||||
output: ((a: RegExpExecArray) => string)[];
|
output: (a: RegExpExecArray) => string[];
|
||||||
id: (a: RegExpExecArray) => number;
|
id: (a: RegExpExecArray) => number;
|
||||||
subtask: (a: RegExpExecArray) => number;
|
subtask: (a: RegExpExecArray) => number;
|
||||||
preferredScorerType: (a: RegExpExecArray) => 'min' | 'max' | 'sum';
|
preferredScorerType: (a: RegExpExecArray) => 'min' | 'max' | 'sum';
|
||||||
@@ -244,47 +244,35 @@ interface MatchRule {
|
|||||||
|
|
||||||
const SubtaskMatcher: MatchRule[] = [
|
const SubtaskMatcher: MatchRule[] = [
|
||||||
{
|
{
|
||||||
regex: /^(([A-Za-z0-9._-]*?)(?:(\d*)[-_])?(\d+))\.(in|txt|in\.txt)$/,
|
regex: /^(([A-Za-z0-9._-]*?)(?:(\d*)[-_])?(\d+))\.(in|IN|txt|TXT|in\.txt|IN\.TXT)$/,
|
||||||
output: [
|
output: (a) => ['out', 'ans']
|
||||||
(a) => `${a[1]}.out`,
|
.flatMap((i) => [i, i.toUpperCase(), `${i}.txt`, `${i.toUpperCase()}.TXT`])
|
||||||
(a) => `${a[1]}.out.txt`,
|
.flatMap((i) => [`${a[1]}.${i}`, `${a[1]}.${i}`.replace(/input/g, 'output').replace(/INPUT/g, 'OUTPUT')])
|
||||||
(a) => `${a[1]}.ans`,
|
.concat(a[1].includes('input') ? `${a[1]}.txt`.replace(/input/g, 'output') : null),
|
||||||
(a) => `${a[1]}.ans.txt`,
|
|
||||||
(a) => `${a[1]}.out`.replace(/input/g, 'output'),
|
|
||||||
(a) => (a[1].includes('input') ? `${a[1]}.txt`.replace(/input/g, 'output') : null),
|
|
||||||
],
|
|
||||||
id: (a) => +a[4],
|
id: (a) => +a[4],
|
||||||
subtask: (a) => +(a[3] || 1),
|
subtask: (a) => +(a[3] || 1),
|
||||||
preferredScorerType: (a) => (a[3] ? 'min' : 'sum'),
|
preferredScorerType: (a) => (a[3] ? 'min' : 'sum'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
regex: /^([^\d]*)\.in(\d+)$/,
|
regex: /^([^\d]*)\.(in|IN)(\d+)$/,
|
||||||
output: [
|
output: (a) => [
|
||||||
(a) => `${a[1]}.ou${a[2]}`,
|
`${a[1]}.${a[2] === 'in' ? 'ou' : 'OU'}${a[3]}`,
|
||||||
(a) => `${a[1]}.ou${a[2]}`.replace(/input/g, 'output'),
|
`${a[1]}.${a[2] === 'in' ? 'out' : 'OUT'}${a[3]}`,
|
||||||
(a) => `${a[1]}.out${a[2]}`,
|
].flatMap((i) => [i, i.replace(/input/g, 'output').replace(/INPUT/g, 'OUTPUT')]),
|
||||||
(a) => `${a[1]}.out${a[2]}`.replace(/input/g, 'output'),
|
|
||||||
],
|
|
||||||
id: (a) => +a[2],
|
id: (a) => +a[2],
|
||||||
subtask: () => 1,
|
subtask: () => 1,
|
||||||
preferredScorerType: () => 'sum',
|
preferredScorerType: () => 'sum',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
regex: /^([^\d]*)([0-9]+)([-_])([0-9]+)\.in$/,
|
regex: /^([^\d]*)([0-9]+)([-_])([0-9]+)\.(in|IN)$/,
|
||||||
output: [
|
output: (a) => ['out', 'ans', 'OUT', 'ANS'].flatMap((i) => `${a[1]}${a[2]}${a[3]}${a[4]}.${i}`),
|
||||||
(a) => `${a[1]}${a[2]}${a[3]}${a[4]}.out`,
|
|
||||||
(a) => `${a[1]}${a[2]}${a[3]}${a[4]}.ans`,
|
|
||||||
],
|
|
||||||
id: (a) => +a[4],
|
id: (a) => +a[4],
|
||||||
subtask: (a) => +a[2],
|
subtask: (a) => +a[2],
|
||||||
preferredScorerType: () => 'min',
|
preferredScorerType: () => 'min',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
regex: /^(([0-9]+)[-_](?:.*))\.in$/,
|
regex: /^(([0-9]+)[-_](?:.*))\.(in|IN)$/,
|
||||||
output: [
|
output: (a) => ['out', 'ans', 'OUT', 'ANS'].flatMap((i) => `${a[1]}.${i}`),
|
||||||
(a) => `${a[1]}.out`,
|
|
||||||
(a) => `${a[1]}.ans`,
|
|
||||||
],
|
|
||||||
id: (a) => +a[2],
|
id: (a) => +a[2],
|
||||||
subtask: () => 1,
|
subtask: () => 1,
|
||||||
preferredScorerType: () => 'sum',
|
preferredScorerType: () => 'sum',
|
||||||
@@ -329,12 +317,12 @@ export function readSubtasksFromFiles(files: string[], config) {
|
|||||||
const sid = rule.subtask(data);
|
const sid = rule.subtask(data);
|
||||||
const c = { input: file, output: '', id: rule.id(data) };
|
const c = { input: file, output: '', id: rule.id(data) };
|
||||||
const type = rule.preferredScorerType(data);
|
const type = rule.preferredScorerType(data);
|
||||||
for (const func of rule.output) {
|
const outputs = (config.noOutputFile ? ['/dev/null'] : rule.output(data)).filter((i) => i);
|
||||||
if (config.noOutputFile) c.output = '/dev/null';
|
for (const output of outputs) {
|
||||||
else c.output = func(data);
|
if (output === file) continue;
|
||||||
if (c.output === file) continue;
|
if (output === '/dev/null' || files.includes(output)) {
|
||||||
if (c.output === '/dev/null' || files.includes(c.output)) {
|
|
||||||
match = true;
|
match = true;
|
||||||
|
c.output = output;
|
||||||
if (!subtask[sid]) {
|
if (!subtask[sid]) {
|
||||||
subtask[sid] = {
|
subtask[sid] = {
|
||||||
time: config.time,
|
time: config.time,
|
||||||
|
|||||||
Reference in new issue
Block a user