题解 | #合法IP#

合法IP

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

ip1 = list(input().split('.'))
#print(ip1)
ip2 = []
flag = 0

#print(ip1)
for i in ip1:
    if i == '':
        flag = 0
        break
    elif i[0] == '0' and len(i) >= 2:
        flag = 0
        break
    elif len(ip1) != 4:
        flag = 0
        break
    elif not i.isdigit():
        flag = 0
        break
else:
    ip2 = list(map(int, ip1))
    for i in ip2:
        if 0 <= i <= 255:
            flag = 1
        else:
            flag = 0
            break

if flag == 0:
    print('NO')
else:
    print('YES')

全部评论

相关推荐

11-08 13:58
门头沟学院 Java
程序员小白条:竟然是蓝桥杯人才doge,还要花钱申领的offer,这么好的公司哪里去找
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务