题解 | #合法IP#
合法IP
https://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9
import re def checkip(ipl): if len(ipl)!=4: print('NO') return for i in ipl: if len(i)>1 and i.startswith('0'): print('NO') return elif not re.search('[0-9]',i[0]): print('NO') return i = int(i) if i < 0 or i > 255: print('NO') return else: return True try: ipl = input().split('.') if checkip(ipl): print('YES') except: print('NO')