题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import sys
hex: str = ''
hex_dict = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}
for line in sys.stdin:
hex = line.strip()[2:]
length = len(hex)
digit = 0
for i in range(length):
exp = 16 ** (length - 1 - i)
if hex[i].isnumeric():
digit += int(hex[i]) * exp
else:
digit += hex_dict[hex[i]] * exp
print(digit)
查看11道真题和解析