Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _03.Maximum_and_Minimum_Element
- {
- class MaximumAndMinimumElement
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Stack<int> stack = new Stack<int>();
- for (int i = 0; i < n; i++)
- {
- int[] commands = Console.ReadLine().Split().Select(int.Parse).ToArray();
- if (commands[0] == 1)
- {
- stack.Push(commands[1]);
- }
- else if (commands[0] == 2 && stack.Any())
- {
- stack.Pop();
- }
- else if (commands[0] == 3)
- {
- Console.WriteLine(stack.Max());
- }
- else if (commands[0] == 4)
- {
- Console.WriteLine(stack.Min());
- }
- }
- int count = stack.Count();
- int a = 1;
- foreach (int value in stack)
- {
- Console.Write(value);
- if (a <= count - 1)
- {
- Console.Write(", ");
- a++;
- }
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement