题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
http://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
一次转化即可!
while True:
try:
s1, s2 = input().split('.'), input()
res1 = 0
base = 1
s1.reverse()
for s in s1:
res1 += int(s) * base
base *= (2 ** 8)
s2 = bin(int(s2))[2:]
s2 = '{:0>32}'.format(s2)
res2 = [str(int(s2[i:i+8], 2)) for i in range(0, len(s2), 8)]
res2 = '.'.join(res2)
print(res1)
print(res2)
except:
break