题解 | 【模板】队列操作

【模板】队列操作

https://www.nowcoder.com/practice/1137c8f6ffac4d5d94cc1b0cb08723f9

public class Program {
    public static void Main() {
        string line = System.Console.ReadLine();
        int q = int.Parse(line);
        System.Collections.Generic.Queue<long> queue = new
        System.Collections.Generic.Queue<long>();

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

            if (op == 1) {
                long x = long.Parse(num[1]);
                queue.Enqueue(x);
            } else if (op == 2) {
                if (queue.Count == 0) {
                    System.Console.WriteLine("ERR_CANNOT_POP");
                } else {
                    queue.Dequeue();
                }
            } else if (op == 3) {
                if (queue.Count == 0) {
                    System.Console.WriteLine("ERR_CANNOT_QUERY");
                } else {
                    System.Console.WriteLine(queue.Peek());
                }
            } else if (op == 4) {
                System.Console.WriteLine(queue.Count);
            }
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
04-03 09:32
已编辑
华南农业大学 golang
我的代码出BUG了:"晚点发个邮件调整一下时间",你收到新的邮件没,如果没有收到新的邮件,那就需要进入面试链接留痕,否则系统会判定你迟到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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