Skip to content

Commit

Permalink
Add support for gym problems (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
nullchilly authored Dec 22, 2024
1 parent 5d0fed3 commit cbf9124
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,18 @@ export const submitToCodeForces = async () => {

/** Get the problem name ( like 144C ) for a given Codeforces URL string. */
export const getProblemName = (problemUrl: string): string => {
const parts = problemUrl.split('/');
let problemName: string;

if (parts.find((x) => x == 'contest')) {
// Url is like https://codeforces.com/contest/1398/problem/C
problemName = parts[parts.length - 3] + parts[parts.length - 1];
} else {
// Url is like https://codeforces.com/problemset/problem/1344/F
problemName = parts[parts.length - 2] + parts[parts.length - 1];
const regexPatterns = [
/\/contest\/(\d+)\/problem\/(\w+)/,
/\/problemset\/problem\/(\d+)\/(\w+)/,
/\/gym\/(\d+)\/problem\/(\w+)/,
];

for (const regex of regexPatterns) {
const match = problemUrl.match(regex);
if (match) {
return match[1] + match[2];
}
}

return problemName;
return '';
};

0 comments on commit cbf9124

Please sign in to comment.