题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
# 10.0.3.193 # 00001010 00000000 00000011 11000001 # 167773121 def ip_int(s): # s = list(map(int,input().split('.'))) ss ='' for i in s: ss += bin(i)[2:].zfill(8) return int(ss,2) # 167969729 # 10.3.3.193 def int_ip(x): #x = int(input()) # 167969729 ls = [] xx = bin(x)[2:].zfill(32) for i in range(0,len(xx),8): ls.append(int(xx[i:i+8],2)) lst = list(map(str,ls)) res = ('.'.join(lst)) return res s = list(map(int,input().split('.'))) # 10.0.3.193 x = int(input()) # 167969729 print(ip_int(s)) print(int_ip(x))