题解 | 【模板】序列操作

【模板】序列操作

https://www.nowcoder.com/practice/12da4185c0bb45918cfdc3072e544069

q = int(input())
ans = []
for _ in range(q):
    p = list(map(int,input().split()))
    if p[0]==1:
        ans.append(p[1])
    elif p[0]==2:
        del(ans[-1])
    elif p[0]==3:
        print(ans[p[1]])
    elif p[0]==4:
        ans.insert(p[1]+1,p[2])
    elif p[0]==5:
        ans.sort()
    elif p[0]==6:
        ans.sort(reverse=True)
    elif p[0]==7:
        print(len(ans))
    elif p[0]==8:
        print(' '.join(map(str,ans)))
    else:
        print(-1)

全部评论

相关推荐

浩浩没烦恼:一二面加起来才一个小时? 我一面就一个小时多了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务