有点乱,可以拆分成多个函数
while True:
try:
found = True
mask = list(map(int, input().strip().split('.')))
ip1 = list(map(int, input().strip().split('.')))
ip2 = list(map(int, input().strip().split('.')))
for i in range(len(mask)):
if mask[i]<0 or ip1[i]<0 or ip2[i]<0 or mask[i]>255 or ip1[i]>255 or ip2[i]>255:
print(1)
found = False
break
mask[i] = bin(mask[i]).replace('0b', '').rjust(8,'0')
ip1[i] = bin(ip1[i]).replace('0b', '').rjust(8,'0')
ip2[i] = bin(ip2[i]).replace('0b', '').rjust(8,'0')
if not found:
continue
mask__ = ''.join(mask)
for i in range(len(mask__)):
if mask__[-1] == '0':
mask__= mask__[:len(mask__)-1]
else:
break
if '0' in mask__:
print(1)
found = False
if not found:
continue
for i,j,k in zip(mask,ip1,ip2):
first,second = '',''
for x in range(len(i)):
if int(i[x]) and int(j[x]):
first += str(i[x])
else:
first += '0'
if int(i[x]) and int(k[x]):
second += str(i[x])
else:
second += '0'
if first != second:
print(2)
found = False
break
if not found:
continue
else:
print(0)
except:
break


京公网安备 11010502036488号