解法一:
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)
解法一:
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)