题解 | #整数与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))

全部评论

相关推荐

买蜜雪也用卷:我觉得应该没有哪个人敢说自己熟练使用git,代码分支一复杂还是得慢慢寻思一下的,不过基本的拉代码提交代码还有分支什么的是应该会
点赞 评论 收藏
分享
06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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