Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace MaximumAndMinimumElement
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Stack<int> stack = new Stack<int>();
- for (int i = 0; i < n; i++)
- {
- string input = Console.ReadLine();
- if (input.Length == 1)
- {
- int[] array = input.Split().Select(int.Parse).ToArray();
- int command = array[0];
- while (stack.Any())
- {
- if (command == 2)
- {
- stack.Pop();
- break;
- }
- else if (command == 3)
- {
- Console.WriteLine(stack.Max());
- break;
- }
- else if (command == 4)
- {
- Console.WriteLine(stack.Min());
- break;
- }
- }
- }
- else
- {
- int[] array = input.Split().Select(int.Parse).ToArray();
- int command = array[0];
- int number = array[1];
- stack.Push(number);
- }
- }
- Console.WriteLine(string.Join(", ", stack));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement