牛客网学习笔记——中等题(字符串)
HJ33 整数与IP地址间的转换
我写的ip转数字
t = list(map(int,input().split('.')))
def turn_2(t):
re = ''
while t > 0:
if t % 2 == 0:
re = '0' + re
else:
re = '1' + re
t //= 2
k = 8 - len(re)
re = '0'*k + re
return re
res = ''
for i in range(len(t)):
res += turn_2(t[i])
re = 0
n = 0
for i in range(len(res)-1,-1,-1):
if res[i] == '1':
re
共有 0 条评论