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