题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
http://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
str_list = input().split('.') ip = input() def transfer(num,count=8): str1 = bin(int(num))[2:] while len(str1)<count: str1 = '0' + str1 return str1 num = '' for i in str_list: num += transfer(i) print(int(num,2)) ip = transfer(ip,32) ip1 = ip[:8] ip2 = ip[8:16] ip3 = ip[16:24] ip4 = ip[24:] print('{0}.{1}.{2}.{3}'.format(int(ip1,2),int(ip2,2),int(ip3,2),int(ip4,2)))