diff --git a/src/submit.ts b/src/submit.ts index 5527dc6..cae77cd 100644 --- a/src/submit.ts +++ b/src/submit.ts @@ -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 ''; };