题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import sys
mapping = {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
'5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15
}
for x in sys.stdin:
# 常规方法
x = x.strip().lower().replace('0x', '')
if not x:
continue
v = 0
for i, char in enumerate(reversed(list(x))):
v += mapping[char] * 16 ** i
print(v)
# 极简方法
# print(int(x, 16))