25选择题,我算法卷子考了一大堆操作系统Linux题,菜鸡直接随机选择
3道编程题,菜鸡是100%,90%,100%
第一题很简单,有一组课程难度,要求先排序,还要求相邻难度不超过4,最后输出排序后数组和能不能达到要求
先排序,再看相邻差值是不是小于4
n = int(input().strip())
li = list()
for _ in range(n):
li.append(int(input().strip()))
li.sort()
tmp=0
for i in range(1, len(li)):
tmp = max(tmp, li[i]-li[i-1])
print(' '.join(map(str, li)))
if tmp<=4:
print(1)
else:
print(0)
第二题是lc原题,基本计算器三, 就是哪个要开会员才能看的哪个题,我没做过临场写的,过了90%,还有10%不知道为啥过不了
s = input().strip()
def find(start, s):
tmp = ''
while start < len(s):
if s[start] == ' ':
start += 1
continue
elif s[start].isdigit():
tmp += s[start]
start += 1
else:
break
return int(tmp), start
def compute(s):
stack = list()
i = 0
mul = False
di = False
while i < len(s):
if s[i] in [' ', '+']:
pass
elif s[i] == '*':
mul = True
elif s[i] == '/':
di = True
elif s[i].isdigit()&nbs***bsp;s[i] == '-':
if s[i].isdigit():
cur, i = find(i, s)
else:
cur, i = find(i + 1, s)
cur = -cur
if mul:
top = stack.pop()
stack.append(top * cur)
mul = False
elif di:
top = stack.pop()
stack.append(top // cur)
di = False
else:
stack.append(cur)
continue
i += 1
return sum(stack)
def kuo(start, s):
s2 = ''
i = start
while i < len(s):
if s[i] == '(':
item, i = kuo(i + 1, s)
s2 += item
elif s[i] == ')':
i += 1
break
else:
s2 += s[i]
i += 1
ans = compute(s2)
return str(ans), i
ans, j = kuo(0, s)
print(int(ans))
第三题华强买瓜,瓜有4个特征,比如id0,1,2,3,最后要求二分类输出0,1(瓜甜不甜),题目给了9组数据,然后让用贝叶斯求答案。菜鸡代码写的太差就不放上来了
#提前批##科大讯飞笔试##算法工程师##图像算法工程师#