第一题 找数 36%
T = int(input()) for _ in range(T): n, k = map(int, input().split()) num = list(map(int,input().split())) num.sort() if n==k: if num[n-1]+1 <= n: print(num[n-1]+1) else: print('NO') else: # 主要报错部分 if num[k-1]+1 >= 1 and num[k-1]+1 <= n and num[k-1]+1 <= num[k]: print('YES') print(num[k-1]+1) else: print('NO')第二题 奇怪键盘 100%
a = str(input()) ans1 = [] ans = [] # 删除空格 for i in range(len(a)): if a[i] != ' ': ans1.append(a[i]) # 删除重复元素 for j in range(len(ans1)): if j==0: ans.append(ans1[0]) elif ans1[j] != ans1[j-1]: ans.append(ans1[j]) # 列表转化为字符串 out = ''.join(b for b in ans) print(out)
第三题 序列prev题 64%
n = int(input()) num = list(map(int, input().split())) prev = [0] * n sum = 0 for i in range(1,n): num1 = num[0:i] num1.sort() for j in range(len(num1)): if num1[len(num1)-1-j] < num[i]: prev[i] = num1[len(num1)-1-j] break sum += (i+1)*prev[i] print(sum)
第四题 漂亮序列左右一半相同 18%
n = int(input()) num = list(map(int, input().split())) ans = 0 L = [] for i in range(n//2): if num[i] != num[i+n//2] and num[i] not in L: ans += 1 L.append(num[i]) print(ans)
全部评论
(4) 回帖