题解 | #复数集合#

复数集合

https://www.nowcoder.com/practice/abdd24fa839c414a9b83aa9c4ecd05cc

def ma(se):  # 求模长最大
    ans = []
    for i in range(len(se)):
        if "+" in se[i]:
            x = se[i].split("+")
            a = int(x[0]) ** 2 + int(x[1][1:]) ** 2
            ans.append(a)
        if "-" in se[i]:
            x = se[i].split("-")
            a = int(x[0]) ** 2 + int(x[1][1:]) ** 2
            ans.append(a)
    ind = 0
    max = 0
    for i in range(len(ans)):
        if ans[i] > max:
            ind = i
            max = ans[i]
    return ind


n = int(input())
se = []
for i in range(n):
    x = input()
    if x[0] == "I":  # 执行Insert
        el = (x.split(" "))[1]
        se.append(el)
        print("SIZE = ", end="")
        print(len(se))
    else:  # 执行Pop
        if len(se) == 0:
            print("empty")
        else:
            print(se[ma(se)])
            del se[ma(se)]
            print("SIZE = ", end="")
            print(len(se))

全部评论

相关推荐

点赞 评论 收藏
分享
吴offer选手:我卡在笔试才是最好笑的,甚至没给我发过笔试链接
投递哔哩哔哩等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务