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

整数与IP地址间的转换

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

def func(lst):
    s=""
    for i in lst:
        s+=i.replace('0b','').zfill(8)
    print(int(s,2))


def fc(s2):
    s = bin(int(s2))
    s=s.replace('0b','').zfill(32)
    n = f'{int(s[:8],2)}.{int(s[8:16],2)}.{int(s[16:24],2)}.{int(s[24:],2)}'
    print(n)
while 1:
    try:
        s = [bin(int(i)) for i in input().split('.')]
        func(s)
        s2 = input()
        fc(s2)
    except:
        break
全部评论

相关推荐

评论
3
1
分享

创作者周榜

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