File tree 1 file changed +12
-10
lines changed
1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -88,16 +88,18 @@ export const submitToCodeForces = async () => {
88
88
89
89
/** Get the problem name ( like 144C ) for a given Codeforces URL string. */
90
90
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
+ / \/ c o n t e s t \/ ( \d + ) \/ p r o b l e m \/ ( \w + ) / ,
93
+ / \/ p r o b l e m s e t \/ p r o b l e m \/ ( \d + ) \/ ( \w + ) / ,
94
+ / \/ g y m \/ ( \d + ) \/ p r o b l e m \/ ( \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
+ }
100
102
}
101
103
102
- return problemName ;
104
+ return '' ;
103
105
} ;
You can’t perform that action at this time.
0 commit comments