1.
#lst 为n个整数,k为差值
def diff(lst, k):
newlist = [i + k for i in lst]
return len(set(lst) & set(newlist))
2.
3.
#n为算式的结果,eval()可以将字符串算式转化为算式结果
def draw(n):
lib = ["66666", "6...6", "....6","6...."]
dic = {}
target = str(n)
length = len(target)
res = ""
dic[0] = [0,1,1,1,0]
dic[1] = [2,2,2,2,2]
dic[2] = [0,2,0,3,0]
dic[3] = [0,2,0,2,0]
dic[4] = [1,1,0,2,2]
dic[5] = [0,3,0,2,0]
dic[6] = [0,3,0,1,0]
dic[7] = [0,2,2,2,2]
dic[8] = [0,1,0,1,0]
dic[9] = [0,1,0,2,0]
for i in range(5):
for j in range(length):
num = int(target[j])
if j<length-1:
res +=lib[dic[num][i]]+".."
else:
res += lib[dic[num][i]]
print(res)
res = ""
4.
def put(la,lb):
m1 = sum(la)/len(la)
m2 = sum(lb)/len(lb)
if m1==m2: return False
if m1>m2:
for i in range(len(la)):
if la[i]<m1 and la[i]>m2 and la[i] not in lb:
lb.append(la[i])
la.pop(i)
return True
return False
if m1<m2:
for i in range(len(lb)):
if lb[i]<m2 and lb[i]>m1 and lb[i] not in la:
la.append(la[i])
lb.pop(i)
return True
return False
count = 0
#a,b分别为两个数组
a = [1,2,5]
b = [2,3,4,5,6]
while True:
if put(a,b):
count += 1
else:
print(count)
break
5.
def jump(height, ban):
return height+ 2 * (ban - height)
k=3
h=2
height = 0 #此时高度
l=[1,3,6]
l=sorted(l)
for i in range(k):
cha = []
for j in l:
if 0<j-height<=h:
cha.append(j)
ban = max(cha)
height = jump(height, ban)
print(height)