题解 | #整数与IP地址间的转换#

整数与IP地址间的转换

https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea

s1 = input().split(".")
s2 = input()
s3 = ""
arr1 = []
s4 = bin(int(s2)).replace("0b", "").rjust(32, "0")
for i in s1:
    temp = bin(int(i))
    s3 += temp.replace("0b", "").rjust(8, "0")
for j in range(0, len(s4), 8):
    val = int(s4[j : j + 8], 2)
    arr1.append(str(val))
print(int(s3, 2))
print(".".join(arr1))

全部评论

相关推荐

点赞 评论 收藏
分享
程序员小白条:找的太晚,别人都是大三实习,然后大四秋招春招的,你大四下了才去实习,晚1年
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务