题解 | #36进制加法#
36进制加法
https://www.nowcoder.com/practice/c5db069fd9d64e6e9cf5fd68860abcdd
下次python就不会找不到答案了
# 36直接进1 ,10是a,35是 z n1, n2 = len(A)-1, len(B)-1 carry = 0 res = '' while n1 >= 0 or n2 >= 0 or carry == 1: temp = carry if n1 >= 0: ch = A[n1] if '0' <= ch <= '9': temp += int(ch) else: temp += ord(ch) - ord('a') + 10 if n2 >= 0: ch = B[n2] if '0' <= ch <= '9': temp += int(ch) else: temp += ord(ch) - ord('a') + 10 carry = temp // 36 temp %= 36 if temp > 9: res += chr(temp-10+ord('a')) else: res += str(temp) n1 -= 1 n2 -= 1 return res[::-1] # 结果要反转