Skip to content

Commit 458a95c

Browse files
committed
Add support for gym problems
1 parent 5d0fed3 commit 458a95c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/submit.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,18 @@ export const submitToCodeForces = async () => {
8888

8989
/** Get the problem name ( like 144C ) for a given Codeforces URL string. */
9090
export const getProblemName = (problemUrl: string): string => {
91-
const parts = problemUrl.split('/');
92-
let problemName: string;
93-
94-
if (parts.find((x) => x == 'contest')) {
95-
// Url is like https://codeforces.com/contest/1398/problem/C
96-
problemName = parts[parts.length - 3] + parts[parts.length - 1];
97-
} else {
98-
// Url is like https://codeforces.com/problemset/problem/1344/F
99-
problemName = parts[parts.length - 2] + parts[parts.length - 1];
91+
const regexPatterns = [
92+
/\/contest\/(\d+)\/problem\/(\w+)/,
93+
/\/problemset\/problem\/(\d+)\/(\w+)/,
94+
/\/gym\/(\d+)\/problem\/(\w+)/,
95+
];
96+
97+
for (const regex of regexPatterns) {
98+
const match = problemUrl.match(regex);
99+
if (match) {
100+
return match[1] + match[2];
101+
}
100102
}
101103

102-
return problemName;
104+
return '';
103105
};

0 commit comments

Comments
 (0)