Created
May 19, 2016 17:53
-
-
Save vdonchev/808657a246f3c4669288c88f20751037 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| namespace Shits | |
| { | |
| public static class Shits | |
| { | |
| public static void Main() | |
| { | |
| var elements = new Stack<int>(); | |
| var maximums = new Stack<int>(); | |
| maximums.Push(-1); | |
| var num = int.Parse(Console.ReadLine()); | |
| for (int i = 0; i < num; i++) | |
| { | |
| var command = Console.ReadLine(); | |
| if (command[0] == '1') | |
| { | |
| var element = int.Parse(command.Substring(2)); | |
| if (element >= maximums.Peek()) | |
| { | |
| maximums.Push(element); | |
| } | |
| elements.Push(element); | |
| } | |
| else if (command[0] == '2') | |
| { | |
| var element = elements.Pop(); | |
| if (element == maximums.Peek()) | |
| { | |
| maximums.Pop(); | |
| } | |
| } | |
| else | |
| { | |
| Console.WriteLine(maximums.Peek()); | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment