Skip to content

Commit

Permalink
Add support for NBUT Online Judge
Browse files Browse the repository at this point in the history
  • Loading branch information
jmerle committed Sep 28, 2024
1 parent 6b63fd4 commit a4efc06
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/parsers/contest/NBUTOnlineJudgeContestParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NBUTOnlineJudgeProblemParser } from '../problem/NBUTOnlineJudgeProblemParser';
import { SimpleContestParser } from '../SimpleContestParser';

export class NBUTOnlineJudgeContestParser extends SimpleContestParser {
protected linkSelector = '#problemlist td.br > a';
protected problemParser = new NBUTOnlineJudgeProblemParser();

public getMatchPatterns(): string[] {
return ['https://ac.2333.moe/Contest/view/id/*.xhtml'];
}
}
5 changes: 5 additions & 0 deletions src/parsers/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { KilonovaContestParser } from './contest/KilonovaContestParser';
import { LanqiaoContestParser } from './contest/LanqiaoContestParser';
import { LibreOJContestParser } from './contest/LibreOJContestParser';
import { LuoguContestParser } from './contest/LuoguContestParser';
import { NBUTOnlineJudgeContestParser } from './contest/NBUTOnlineJudgeContestParser';
import { NOJContestParser } from './contest/NOJContestParser';
import { OpenJudgeContestParser } from './contest/OpenJudgeContestParser';
import { PEGJudgeContestParser } from './contest/PEGJudgeContestParser';
Expand Down Expand Up @@ -100,6 +101,7 @@ import { MendoProblemParser } from './problem/MendoProblemParser';
import { MetaCodingCompetitionsProblemParser } from './problem/MetaCodingCompetitionsProblemParser';
import { MrJudgeProblemParser } from './problem/MrJudgeProblemParser';
import { MSKInformaticsProblemParser } from './problem/MSKInformaticsProblemParser';
import { NBUTOnlineJudgeProblemParser } from './problem/NBUTOnlineJudgeProblemParser';
import { NepsAcademyProblemParser } from './problem/NepsAcademyProblemParser';
import { NewtonSchoolProblemParser } from './problem/NewtonSchoolProblemParser';
import { NOJProblemParser } from './problem/NOJProblemParser';
Expand Down Expand Up @@ -276,6 +278,9 @@ export const parsers: Parser[] = [

new MSKInformaticsProblemParser(),

new NBUTOnlineJudgeProblemParser(),
new NBUTOnlineJudgeContestParser(),

new NepsAcademyProblemParser(),

new NewtonSchoolProblemParser(),
Expand Down
29 changes: 29 additions & 0 deletions src/parsers/problem/NBUTOnlineJudgeProblemParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Sendable } from '../../models/Sendable';
import { TaskBuilder } from '../../models/TaskBuilder';
import { htmlToElement } from '../../utils/dom';
import { Parser } from '../Parser';

export class NBUTOnlineJudgeProblemParser extends Parser {
public getMatchPatterns(): string[] {
return ['https://ac.2333.moe/Problem/view.xhtml*', 'https://ac.2333.moe/Contest/view/id/*/problem/*.xhtml'];
}

public async parse(url: string, html: string): Promise<Sendable> {
const elem = htmlToElement(html);
const task = new TaskBuilder('NBUT Online Judge').setUrl(url);

task.setName(elem.querySelector('#title > h3').textContent);

const limitsStr = elem.querySelector('#limit').textContent;
task.setTimeLimit(parseInt(/(\d+) ms/.exec(limitsStr)[1]));
task.setMemoryLimit(Math.round(parseInt(/(\d+) K/.exec(limitsStr)[1]) / 1024));

const sampleInput = elem.querySelector('#sampleinput > pre');
const sampleOutput = elem.querySelector('#sampleoutput > pre');
if (sampleInput !== null && sampleOutput !== null) {
task.addTest(sampleInput.textContent, sampleOutput.textContent);
}

return task.build();
}
}

0 comments on commit a4efc06

Please sign in to comment.