Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace BasicStackOperations
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] commands = Console.ReadLine()
- .Split(new string[] { " ", "/t" }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int numbersToAdd = commands[0];
- int numbersToPop = commands[1];
- int numbersToSearchFor = commands[2];
- int[] numbers = Console.ReadLine()
- .Split(new string[] { " ","/t" }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- Stack<int> stack = new Stack<int>();
- for (int i = 0; i < numbersToAdd; i++)
- {
- stack.Push(numbers[i]);
- }
- for (int i = 0; i < numbersToPop; i++)
- {
- stack.Pop();
- }
- if (stack.Count == 0)
- {
- Console.WriteLine(0);
- return;
- }
- if (stack.Contains(numbersToSearchFor))
- {
- Console.WriteLine("true");
- }
- else
- {
- Console.WriteLine(stack.Min());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement