题目描述
blablabla
样例
# 用于输入解析,将大写字母A-Z对应到十进制数值10-35
input_dict = {chr(i): i - ord('A') + 10 for i in range(ord('A'), ord('Z') + 1)}
# 用于输出转换,将十进制数值10-35对应到小写字母a-z
output_dict = {i: chr(i - 10 + ord('a')) for i in range(10, 36)}
M, N = map(int, input().split())
X = input()
def conv(s, m):
s = s[::-1]
r = 0
base = 1
for item in s:
if ord(item) >= ord('0') and ord(item) <= ord('9'):
r += base * (ord(item) - ord('0'))
else:
r += base * input_dict[item]
base *= m
return r
def conv2(r, m):
s = ""
while r > 0:
x = r % m
if x < 10:
s = chr(x + ord('0')) + s
else:
s = output_dict[x] + s
r //= m
return s
r = conv(X, M)
print(conv2(r, N))
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla