题解 | #合法IP#

合法IP

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

# -*-coding:utf-8-*-
import math , string

while True:
    try:
        ip_str = input().split(".")
        if len(ip_str) == 4 :
            for ip in ip_str:
                if not ip.isalnum():
                    print("NO")
                    break
                if int(ip) not in range(0,256):
                    print("NO")
                    break
                if len(ip)>1 and ip[0] == '0':
                    print("NO")
                    break
            else:
                print("YES")
        else:
            print("NO")




    except:
        break

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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