Skip to content

Instantly share code, notes, and snippets.

@vdonchev
Created May 19, 2016 17:53
Show Gist options
  • Select an option

  • Save vdonchev/808657a246f3c4669288c88f20751037 to your computer and use it in GitHub Desktop.

Select an option

Save vdonchev/808657a246f3c4669288c88f20751037 to your computer and use it in GitHub Desktop.
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