7-10 sdut-汉明距离
知识点:
转化为指定长度的二进制
代码:
import string
a,b=map(int,input().split())
maxn=max(a,b)
cnt1=list(format(a,"031b"))
cnt2=list(format(b,"031b"))
ans=0
for i in range(31):
if cnt1[i]!=cnt2[i]:
ans+=1
print(ans)
转化为指定长度的二进制
import string
a,b=map(int,input().split())
maxn=max(a,b)
cnt1=list(format(a,"031b"))
cnt2=list(format(b,"031b"))
ans=0
for i in range(31):
if cnt1[i]!=cnt2[i]:
ans+=1
print(ans)