题解 | 【模板】序列操作

【模板】序列操作

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

import sys

res = []
for line in sys.stdin:
    a = line.split()
    if int(a[0]) == 1:
        res.append(int(a[1]))
    elif int(a[0]) == 2:
        if len(res) >= 1:
            res.pop()
    elif int(a[0]) == 3:
        print(int(res[int(a[1])]))
    elif int(a[0]) == 4:
        res.insert(int(a[1])+1, int(a[2]))
    elif int(a[0]) == 5:
        res = sorted(res)
    elif int(a[0]) == 6:
        res = sorted(res, reverse=True)
    elif int(a[0]) == 7:
        print(len(res))
    elif int(a[0]) == 8:
            print(*res) 


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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