题解 | 整数与IP地址间的转换
import sys def ip2int(ip:str): bin_str = [bin(int(i))[2:].zfill(8) for i in ip.split('.')] return int(''.join(bin_str), 2) def int2ip(val:int): res = [] for i in range(3, -1, -1): d, rmd = divmod(val, 256**i) res.append(d) val = rmd return '.'.join([str(i) for i in res]) raw_input = [] for i,line in enumerate(sys.stdin): raw_input.append(line.strip()) if i == 1: break print(ip2int(raw_input[0])) print(int2ip(int(raw_input[1])))