题解 | 【模板】序列操作

【模板】序列操作

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

public class Program {
    public static void Main() {
        string line = System.Console.ReadLine();
        int q = int.Parse(line);

        System.Collections.Generic.List<int> list = new
        System.Collections.Generic.List<int>();

        for (int i = 0; i < q; i++) {
            string[] parts = System.Console.ReadLine().Split();
            int op = int.Parse(parts[0]);

            if (op == 1) {
                int x = int.Parse(parts[1]);
                list.Add(x);
            } else if (op == 2) {
                list.RemoveAt(list.Count - 1);
            } else if (op == 3) {
                int idx = int.Parse(parts[1]);
                System.Console.WriteLine(list[idx]);
            } else if (op == 4) {
                int idx = int.Parse(parts[1]);
                int x = int.Parse(parts[2]);    
                list.Insert(idx + 1, x);
            } else if (op == 5) {
                list.Sort();
            } else if (op == 6) {
                list.Sort((a, b) => b.CompareTo(a));
            } else if (op == 7) {
                System.Console.WriteLine(list.Count);
            } else if (op == 8) {
                System.Console.WriteLine(string.Join(" ", list));
            }
        }
    }
}

全部评论

相关推荐

牛客62533758...:华为不卡双非,而是卡院校hhhh
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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