Exemplo n.º 1
0
        public static void MainTest(string[] args)
        {
            int n = StdIn.ReadInt();

            int[] seq = new int [n];
            for (int i = 0; i < n; i++)
            {
                seq[i] = StdIn.ReadInt();
            }
            int m = StdIn.ReadInt();

            Queue q = new Queue(n);

            for (int i = 0; i < m; i++)
            {
                q.Enqueue(seq[i]);
            }
            Console.Write(q.Max());

            for (int i = m; i < n; i++)
            {
                q.Dequeue();
                q.Enqueue(seq[i]);
                Console.Write(" " + q.Max());
            }

            Console.WriteLine($"{n}");
            Console.WriteLine($"{seq.Aggregate("", (s, i) => s.Length > 0 ? $"{s},{i}" : i.ToString())}");
            Console.WriteLine($"{m}");
        }
Exemplo n.º 2
0
        //TestFile("01");
        //TestFile("02");
        public static void MainTest(string[] args)
        {
            int          q     = StdIn.ReadInt();
            StackWithMax stack = new StackWithMax();

            for (int i = 0; i < q; i++)
            {
                string op = StdIn.ReadString();
                if (op.Equals("push"))
                {
                    stack.Push(StdIn.ReadInt());
                }
                if (op.Equals("pop"))
                {
                    stack.Pop();
                }
                if (op.Equals("max"))
                {
                    Console.WriteLine(stack.Max());
                }
            }
        }