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

整数与IP地址间的转换

https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea?tpId=37&tqId=21256&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fdifficulty%3D3%26page%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=3&judgeStatus=undefined&tags=&title=

ip = input()
ans = 0
for s in ip.split("."):
    ans = ans * 256 + int(s)
print(ans)

arr = []
num = int(input())
for i in range(4):
    arr.append(str(num % 256))
    num //= 256
print(".".join(arr[::-1]))

全部评论

相关推荐

gcniz:一天写两千行你闹呢
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务