Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- int count = int.Parse(Console.ReadLine());
- Stack<int> stack = new Stack<int>();
- int min = int.MaxValue;
- int max = int.MinValue;
- for (int i = 0; i < count; i++)
- {
- int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
- if (input[0] == 1)
- {
- stack.Push(input[1]);
- }
- if (input[0] == 2)
- {
- stack.Pop();
- }
- if (input[0] == 3)
- {
- if (stack.Any())
- {
- foreach (var item in stack)
- {
- if (item > max)
- {
- max = item;
- }
- }
- Console.WriteLine(max);
- }
- }
- if (input[0] == 4)
- {
- if (stack.Any())
- {
- foreach (var item in stack)
- {
- if (item < min)
- {
- min = item;
- }
- }
- Console.WriteLine(min);
- }
- }
- }
- Console.WriteLine(string.Join(", ", stack));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement