题解 | #合法IP#
合法IP
https://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9
s = input().split('.')
if "" in s:
print('NO')
else:
if len(s) == 4:
if (len(s[0]) != 1 and (s[0][0] == '0' or s[0][0] == '+')) or (len(s[1]) != 1 and (s[1][0] == '0' or s[1][0] == '+')) or (len(s[2]) != 1 and (s[2][0] == '0' or s[2][0] == '+')) or (len(s[3]) != 1 and (s[3][0] == '0' or s[3][0] == '+')):
print('NO')
else:
ip = list(map(int, s))
y_n = []
for i in ip:
if 0 <= i <= 255:
y_n.append('YES')
else:
y_n.append('NO')
if 'NO' in y_n:
print('NO')
else:
print('YES')
else:
print("NO")
vivo公司福利 368人发布