科大讯飞算法笔试 2022.7.23
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)
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))