题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
直接整除的256。。运行时间受输入影响极大,三次内竟能超过100%和0.08%的python3代码
ip = input().split('.') number = eval(input()) add = 0 num = [] for i in ip: num.append(eval(i)) for j in range(len(num)): add = add + num[j] * 256**(len(num)-j-1) print(add) iplis = [] while(number): yu = number % 256 iplis.append(yu) number = number // 256 a = '' for j in range(len(iplis)): if j != len(iplis)-1: a = a + str(iplis[len(iplis)-j-1]) + '.' else: a = a + str(iplis[len(iplis)-j-1]) print(a)