题解 | #合法IP#
合法IP
http://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9
Python 代码实现:
while True:
try:
IP_list = list(input().split('.'))
if len(IP_list) != 4:
print('NO')
continue
for i in IP_list:
if not i.isdigit():
print('NO')
break
if int(i) < 0 or int(i) > 255:
print('NO')
break
elif i.startswith('0') and not i.endswith('0'):
print('NO')
break
else:
print('YES')
except:
break