python 求调
  • 板块学术版
  • 楼主Henry_ji
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/7/21 22:27
  • 上次更新2023/10/27 18:59:59
查看原帖
python 求调
373484
Henry_ji楼主2022/7/21 22:27

代码本地编译通过,但提交后显示RE

def change(tempN):
    t = 1
    s = 0
    for i in range(len(tempN) - 1, -1, -1):
        s += (ord(tempN[i]) - ord('a')) * t
        t *= 26
    return s


def create_checkList(nList):
    checkList = [0] * 456975
    for n in nList:
        if type(n) == type(0):
            checkList[n] = 1
        elif not checkList[change(n)]:
            checkList[change(n)] = n
    return checkList


def solve(n, nList):
    output = ''
    oriList = []
    for i in range(n):
        tempN = nList[i]
        if tempN[0] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
            oriList.append(int(tempN))
            nList[i] = int(tempN)
        else:
            oriList.append(tempN)
            nList[i] = change(tempN)
    checkList = create_checkList(oriList)
    sortedList = sorted(nList, reverse=True)
    t = 1
    for i in range(n):
        p = (i + 1) // 2
        p *= t
        tempN = sortedList[p]
        if checkList[tempN] == 1:
            output += str(tempN) + '\n'
        elif checkList[tempN] != -1:
            output += str(checkList[tempN]) + '\n'
        checkList[tempN] = -1
        t *= -1
    return output


n = eval(input())
nList = []
for i in range(n):
    nList.append(input())
print(solve(n, nList))

问题大概率出现在 create_checkList 函数中

2022/7/21 22:27
加载中...