题解 | #合法IP#

合法IP

https://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9

try:  # 就通过显示的用例一点一点加条件
    res = 'YES'
    stri = input().split('.')
    for i in stri:
        if i[0] == "0" and len(i)>1:
            res = 'NO'

    for i in stri:
        if not i[0].isdigit():
            res = "NO"
    arr = list(map(int ,stri))


    if len(arr)!=4:
        res = 'NO'

    for i in arr:
        if not 0<=i<=255:
            res = "NO"

    print(res)  
except:
    print('NO')

全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务