一、题目
二、示例
三、代码
# 定义IP地址转化为10进制子函数
def funIp_10(s):
s = map(int, s.split('.'))
temp = '0' * 8
res = []
for i in s:
temp += bin(i)[2:]
res.append(temp[-8:])
temp = '0' * 8
res = ''.join(res)
int1 = 0
for i in range(32):
int1 += int(int(res[31 - i]) * (2) ** i)
return int1
# 定义十进制转化为IP地址子函数
def fun10_Ip(n):
res = []
temp = '0' * 32
temp += bin(int(n))[2:]
temp = temp[-32:]
res += [temp[i:i+8] for i in range(0,32,8)]
ip = []
for i in res:
ip.append(str(int(i, 2)))
return '.'.join(ip)
# 主函数
while True:
try:
Ip = input()
n = input()
print(funIp_10(Ip))
print(fun10_Ip(n))
except:
break
四、算法说明
不想写了,偷个懒,自己看程序吧,看不懂评论区问我,谢谢!
胡萝卜
2022年3月10日15:19:40
我不知道将去向何方,但我已在路上! |
---|
时光匆匆,虽未曾谋面,却相遇于斯,实在是莫大的缘分,感谢您的到访 ! |