题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
解法一:
string = input() print(int(string, 16))
解法二:
d = {'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15} string = input() ans = 0 for ch in string[2:]: if str.isdigit(ch): ans = ans * 16 + int(ch) else: ans = ans * 16 + d[ch.lower()] print(ans)