core&ui: fix contest with more than 26 problems have wrong alphabetic id (#1008)

Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
Bhscerandundefined authored and GitHub committed 2025-07-07 15:31:46 +01:00
1 parent 627ce77d30
commit dc6345c0b3
11 files changed
+30 -18

No files matched your search

+9
View File
@@ -236,3 +236,12 @@ export function sortFiles(files: Record<string, any>[] | string[], key = '_id')
});
return result.map((x) => (isString ? x.name : (delete x._weights && x)));
}
export const getAlphabeticId = (() => {
// A...Z, AA...AZ, BA...BZ, ...
const f = (a: number) => (a < 0 ? '' : f(a / 26 - 1) + String.fromCharCode((a % 26) + 65)) as string;
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const cache = alphabet.split('');
for (const ch of alphabet) cache.push(...alphabet.split('').map((c) => ch + c));
return (i: number) => cache[i] || (i < 0 ? '?' : f(i));
})();