题解 | #字符串排序#
整数与IP地址间的转换
http://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
def f(): while True: try: ip = list(map(int, input().split('.'))) intip = int(input()) temp1 = '' for i in ip: temp = bin(i) temp1 += (8 - len(temp[2:])) * '0' +temp[2:] print(int(temp1, 2)) temp2 = bin(intip)[::-1] ip4 = '0b' + temp2[:8][::-1] ip3 = '0b' + temp2[8:16][::-1] ip2 = '0b' + temp2[16:24][::-1] ip1 = '0b' + temp2[24:len(temp2) - 2][::-1] res2 = str(int(ip1, 2)) + '.' + str(int(ip2,2)) + '.' + str(int(ip3,2))+'.'+str(int(ip4,2)) print(res2) except: break
f()
