Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _02.BasicStackOperations
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var input = Console.ReadLine()
  12. .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  13. .Select(int.Parse)
  14. .ToArray();
  15.  
  16. var numbers = Console.ReadLine()
  17. .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  18. .Select(int.Parse)
  19. .ToArray();
  20.  
  21. var push = input[0];
  22. var pop = input[1];
  23. var find = input[2];
  24. var stack = new Stack<int>();
  25.  
  26. PushNumbers(numbers, push, stack);
  27. PopNumbers(numbers, pop, stack);
  28.  
  29. if (stack.Contains(find))
  30. {
  31. Console.WriteLine("true");
  32. }
  33. else
  34. {
  35. Console.WriteLine(stack.Min());
  36. }
  37.  
  38. }
  39.  
  40. private static void PopNumbers(int[] numbers, int pop, Stack<int> stack)
  41. {
  42. for (int i = 0; i < pop; i++)
  43. {
  44. stack.Pop();
  45. }
  46. }
  47.  
  48. private static void PushNumbers(int[] numbers, int push, Stack<int> stack)
  49. {
  50. for (int i = 0; i < push; i++)
  51. {
  52. stack.Push(numbers[i]);
  53. }
  54. }
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement