题解 | 【模板】队列操作

【模板】队列操作

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.List<long> queue =new System.Collections.Generic.List<long>();
        for(int i=0;i<q;i++){
            string[] num=System.Console.ReadLine().Split();
            int op=int.Parse(num[0]);
            if (op==1){
                int x=int.Parse(num[1]);
                queue.Add(x);
            }else if(op==2){
                if (queue.Count==0){
                    System.Console.WriteLine("ERR_CANNOT_POP");
                }else{
                    queue.RemoveAt(0);
                }
            }else if(op==3){
                if (queue.Count==0){
                    System.Console.WriteLine("ERR_CANNOT_QUERY");
                }else{
                    System.Console.WriteLine(queue[0]);
                }
            }else if(op==4){
                System.Console.WriteLine(queue.Count);
            }
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
caicaidog:现实里没实习的还是占多数的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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