数制转换的关键就是找出对应位置的系数,我这里用的是ascil码
try:
while True:
str1 = str(input())
num1 = []
flag = 0
k = 0
for i in str1:
if flag < 2:
flag += 1
else:
if i != ' ':
k += 1
num1.append(i)
ans = 0
for j in range(k):
if (ord(num1[j]) >= 65 and ord(num1[j]) <= 70):
ans += (ord(num1[j])-ord('A')+10)*(16**(k-j-1))
elif (ord(num1[j]) >= 48 and ord(num1[j]) <= 57):
ans += (ord(num1[j])-ord('0'))*(16**(k-j-1))
elif (ord(num1[j]) >= 97 and ord(num1[j]) <= 122):
ans += (ord(num1[j])-ord('a')+10)*(16**(k-j-1))
else:
ans = ans
print(ans)
except:
pass


京公网安备 11010502036488号