题解 | #合法IP#

合法IP

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

s = input().split('.')
if "" in s:
    print('NO')
else:
    if len(s) == 4:
        if (len(s[0]) != 1 and (s[0][0] == '0' or s[0][0] == '+')) or (len(s[1]) != 1 and (s[1][0] == '0' or s[1][0] == '+')) or (len(s[2]) != 1 and (s[2][0] == '0' or s[2][0] == '+')) or (len(s[3]) != 1 and (s[3][0] == '0' or s[3][0] == '+')):
            print('NO')
        else:
            ip = list(map(int, s))
            y_n = []
            for i in ip:
                if 0 <= i <= 255:
                    y_n.append('YES')
                else:
                    y_n.append('NO')

            if 'NO' in y_n:
                print('NO')
            else:
                print('YES')
    else:
        print("NO")

全部评论

相关推荐

这是什么操作什么意思,这公司我服了...
斯派克spark:意思是有比你更便宜的牛马了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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