题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
将输入的16进制作为字符串进行处理。 构建字典将16进制中的字符转化为数字。
dic = {
'A': 10,
'B': 11,
'C': 12,
'D': 13,
'E': 14,
'F': 15,
}
while True:
try:
raw = list(input())
length = len(raw)
sum = 0
for i in range(length-1, 1, -1):
if raw[i] in dic:
sum += dic[raw[i]]*16**(length-1-i)
else:
sum += int(raw[i])*16**(length-1-i)
print(sum)
except:
break