题解 | #合法IP#
合法IP
https://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9?tpId=37&tqId=21313&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D2%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
import sys #for line in sys.stdin: # a = line.split() # print(int(a[0]) + int(a[1])) s=input() def islegal(s): ''' 将s按.分割分别对其中的每个元素做判断 x不能小于0 x不能大于255 x不能以0开头,长度大于1 x不能不是数字 L的长度不能不等于4 ''' L=s.split(".") if len(L)!=4: print("NO") return False for x in L: if not x.isdigit(): print("NO") return False elif int(x)<0 or int(x)>255 or (x.startswith('0') and len(x) > 1): print("NO") return False print("YES") return True islegal(s)