daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml.XPath;
  7.  
  8. namespace BasicStackOperations
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Stack<int> operations = new Stack<int>(Console.ReadLine().Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
  15.  
  16.             int findElement = operations.Pop();
  17.             int numberOfPops = operations.Pop();
  18.             int numberOfPushes = operations.Pop();
  19.  
  20.             Stack<int> stack = new Stack<int>(Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).Reverse());
  21.  
  22.             Stack<int> result = new Stack<int>();
  23.  
  24.             for (int i = 0; i < numberOfPushes; i++)
  25.             {
  26.                 result.Push(stack.Pop());
  27.             }
  28.  
  29.            
  30.  
  31.             for (int i = 0; i < numberOfPops; i++)
  32.             {
  33.                 result.Pop();
  34.             }
  35.             if (result.Count==0)
  36.             {
  37.                 Console.WriteLine("0");
  38.             }
  39.             else if (result.Contains(findElement))
  40.             {
  41.                 Console.WriteLine("true");
  42.             }
  43.             else
  44.             {
  45.                 Console.WriteLine(result.Min());
  46.             }
  47.  
  48.  
  49.         }
  50.     }
  51. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top