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

全部评论

相关推荐

08-04 22:37
桂林学院 Java
行不行阿细GO:说真的我现在看到校招java简历都头痛。。千篇一律和阅卷高考作文差不多,估计公司也是吧,到最后就看学历和大厂实习了
投递BOSS直聘等公司10个岗位
点赞 评论 收藏
分享
09-12 11:55
已编辑
湖南工商大学 Java
那一天的Java_J...:这种一堆问题的,别去
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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