42分填空,58分编程
填空题基本都是智商题和算法基础,没啥大的难度
四道编程题也不难,基本没用到什么算法,除了第一题LRU看错题意了在50%耗了半天,其他题基本都是1A
没给数据范围,默认全部能暴力,没动什么脑子就过了
九点放代码
UPD:
模拟LRU
30%代码(50%的被覆盖了)
def solve1(): n, m = map(int, input().split()) q = [] for i in range(m): s = input().split() op = s[0] # print(*q) if op == "s": k, v = int(s[1]), int(s[2]) if len(q) < n: q.append([1, k, v]) else: q.sort(reverse=True) q.pop() q.append([1, k, v]) else: temp = int(s[1]) for j in q: if j[1] == temp: print(j[2]) t = j q.remove(j) q.append([t[0] + 1, t[1], t[2]]) break else: print(-1) # pass
模拟正则匹配中的*和.,a串是目标串,b串是模式串,匹配成功输出1,失败则输出0
def solve2(): a = input() b = input() n = len(a) ok = 1 last = "" i, j = 0, 0 while i < n: if a[i] == b[j]: i += 1 j += 1 continue else: if b[j] == ".": i += 1 j += 1 elif b[j] == "*": while i < n and b[j - 1] == a[i]: i += 1 j += 1 else: ok = 0 print(ok)
给定一串数字,求此数字循环往右的过程中的最大值,例如1324循环的结果最大是4132
def solve3(): n = input() mx = -1 for i in n: mx = max(mx, int(i)) pos = [] for i in range(len(n)): if int(n[i]) == mx: pos.append(i) ans = [] for i in pos: ans.append(int(n[i:] + n[:i])) print(max(ans))
给定字符串A和字符串B,求在字符串A中能找到包含字符串B的字串的最小长度(包含字符串B:即该字串含有字符串B的全部字母,不论顺序)
def solve4(): temp = input().split(",") a = temp[0][1:-1] b = temp[1][1:-1] n = len(a) d = [0] * 29 for i in b: d[ord(i) - ord('A')] += 1 ans = [] now = [0] * 29 l, r = 0, 0 def check(): ok = 1 for i in range(28): if now[i] < d[i]: ok = 0 break return ok if b.find(a[l]) != -1: now[ord(a[l]) - ord('A')] += 1 while r < n: ok = 0 for i in range(28): if now[i] < d[i]: ok = 1 break if ok: r += 1 if r < n and b.find(a[r]) != -1: now[ord(a[r]) - ord('A')] += 1 continue ans.append(a[l:r + 1]) while check() and l < n: # print(l) if b.find(a[l]) != -1: now[ord(a[l]) - ord('A')] -= 1 ans.append(a[l:r + 1]) l += 1 # print(ans) mi = 1 << 31 for i in ans: mi = min(mi, len(i)) for i in ans: if len(i) == mi: print(f'"{i}"') return print('""')