C# 백준 10828번 문제 스택
using System;
using System.Collections;
using System.Collections.Generic;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
int cnt = int.Parse(Console.ReadLine());
Stack stack_1 = new Stack(cnt);
for (int i = 0; i < cnt; i++)
{
string[] cmd = Console.ReadLine().Split();
if (cmd[0] == "push")
{
stack_1.Push(cmd[1]);
}
else if (cmd[0] == "pop")
{
if (stack_1.Count == 0)
{
Console.WriteLine("-1");
}
else
{
Console.WriteLine(stack_1.Pop());
}
}
else if (cmd[0] == "size")
{
Console.WriteLine(stack_1.Count);
}
else if (cmd[0] == "empty")
{
if (stack_1.Count == 0)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
}
else if (cmd[0] == "top")
{
if(stack_1.Count == 0)
{
Console.WriteLine("-1");
}
else
{
Console.WriteLine(stack_1.Peek());
}
}
}
}
}
}