bilibili, 算法第二次笔试
第一题:
if __name__ == "__main__": d = list(map(int, input().split(','))) for i in range(len(d)): for j in range(i): if int(str(d[i]) + str(d[j])) > int(str(d[j]) + str(d[i])): d[i], d[j] = d[j], d[i] d = [str(i) for i in d] if len(set(d)) == 1 and set(d).pop() == '0': print("0") else: print("".join(d))
第三题:
if __name__ == "__main__": n, s = [int(x) for x in input().strip().split(' ')] p = [int(x) for x in input().strip().split(' ')] if sum(p) <= s: print(-1) else: res = float('inf') cnt = p[0] l = 0 r = 1 while l < n and r <= n: while r < n and cnt < s: cnt += p[r] r += 1 if cnt >= s: res = min(res, r-l) cnt -= p[l] l += 1 print(res)