题解 | #合法IP#

合法IP

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

# 两行代码过关

# 输入
ips=input().strip().split('.')

#输出(第11次总算找出所有限定条件)
print('YES' if len(ips)==4 and (all(ips[i].isdigit() for i in range(4))) and (all(ips[i][0]!='0' for i in range(4) if len(ips[i])>1)) and (all(bin(int(ip))[2:] if len(bin(int(ip))[2:])<=8 else 0 for ip in ips)) else 'NO')

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务