Imagine an office which issues license plates in the following format and order:
00000, 00001, 00002, ..., 99999,
A0000, A0001, ..., A9999, B0000, ..., Z9999,
AA000, ..., ZZ999,
AAA00, ..., ZZZ99,
AAAA0, ..., ZZZZ9,
AAAAA, ..., ZZZZZ
That is, the sequence is the concatenation of six ranges, where:
- license plates in the first range have 5 digits,
- license plates in the second range have 1 letter followed by 4 digits,
- license plates in the third range have 2 letters followed by 3 digits,
- license plates in the fourth range have 3 letters followed by 2 digits,
- license plates in the fifth range have 4 letters followed by 1 digit, and
- license plates in the sixth range have 5 letters (and 0 digits).
Note that this is not just base-36 conversion. For example, 12CD5 is not a valid license plate. Each range has a fixed number of letters followed by a fixed number of digits.
Write a function that returns the nth license plate in the sequence, given n as the input. n starts from 0, so the function should return:
f(0) -> 00000f(1) -> 00001f(100000) -> A0000f(?) -> ZZZZZ
这道题的核心是把 n 映射到一个“分段编号系统”里:前 100000 个是 5 位数字,之后依次是 1 位字母 + 4 位数字、2 位字母 + 3 位数字,直到 5 位字母。解题时先根据 n 落在哪一段,减去前面所有段的总长度,再把剩余编号分别转换成字母部分和数字部分。字母部分本质上是 26 进制(A 到 Z),数字部分是固定长度的十进制补零输出。整体只需要做分段判断和进制转换,时间复杂度是 O(1) 级别,适合在面试里考察数学建模与字符串格式化能力。