很简单的两道面试题
1个是IP排序。
3.1.1.2
127.0.0.1
1.1.1.1
192.168.0.1
192.167.0.2
60.10.10.10
最简单就是用sort
cat tmp | sort -t. -k1n,1 -k2n,2
2,比较版本号大小
# -*- encoding=utf-8 -*-
a="1.2.33"
b="2.2.123"
alen = len(a.split("."))
blen = len(b.split("."))
if (alen!=blen):
print("ab长度不同")
else:
for num in range(0,alen):
if ((a.split(".")[num]) != (b.split(".")[num])):
if (int(a.split(".")[num]) > int(b.split(".")[num])):
print("A is BIG")
else:
print("B is BIG")