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