Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03.Maximum_and_Minimum_Element
  8. {
  9. class MaximumAndMinimumElement
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. Stack<int> stack = new Stack<int>();
  16.  
  17. for (int i = 0; i < n; i++)
  18. {
  19. int[] commands = Console.ReadLine().Split().Select(int.Parse).ToArray();
  20.  
  21. if (commands[0] == 1)
  22. {
  23. stack.Push(commands[1]);
  24. }
  25. else if (commands[0] == 2 && stack.Any())
  26. {
  27. stack.Pop();
  28. }
  29. else if (commands[0] == 3)
  30. {
  31. Console.WriteLine(stack.Max());
  32. }
  33. else if (commands[0] == 4)
  34. {
  35. Console.WriteLine(stack.Min());
  36. }
  37. }
  38.  
  39. int count = stack.Count();
  40. int a = 1;
  41.  
  42. foreach (int value in stack)
  43. {
  44. Console.Write(value);
  45. if (a <= count - 1)
  46. {
  47. Console.Write(", ");
  48. a++;
  49. }
  50.  
  51.  
  52. }
  53.  
  54. Console.WriteLine();
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement