拼多多笔试求解
第一题不知道哪里出问题了,提交就是0%,有没有大佬帮忙看下!!!!
T = int(input()) for _ in range(T): n,k = list(map(int,input().split())) s = input() lis = [ord(i)-ord('a') for i in s] n = len(lis) tmp = k maxi = 0 for i in range(n): if i==0: if lis[i]<=k: k = k-lis[i] maxi = max(maxi,lis[i]) else: break elif 0<lis[i] - lis[i-1]<=k: k = k-(lis[i] - lis[i-1]) maxi = max(maxi,lis[i]) elif lis[i] - lis[i-1]<=0: continue else: break newl = lis.copy() for x in range(n): if lis[x]<=maxi: newl[x] = 0 elif lis[i]-k<=lis[x]<=lis[i]: newl[x] = lis[i]-k res = '' for x in newl: res += chr(x+ord('a')) print(res)