백준 10828 스택
Console Programming/C# Console 2019. 11. 4. 10:23Program.cs
using System;
namespace _10828
{
class Program
{
static void Main(string[] args)
{
int[] stack = new int[1000];
int cnt = 0;
string[] keyword = new string[] { "push", "pop", "size", "empty", "top" };
int testcase = int.Parse(Console.ReadLine());
for (int i = 0; i < testcase; i++)
{
string[] str2 = (Console.ReadLine()).Split(' ');
for(int j =0; j < keyword.Length; j++)
{
if(str2[0].Equals(keyword[j]))
{
switch (j)
{
case 0:
{
int n = int.Parse(str2[1]);
stack[cnt++] = n;
break;
}
case 1:
{
if (cnt == 0)
{
Console.WriteLine("-1");
break;
}
else
{
Console.WriteLine(stack[--cnt]);
}
break;
}
case 2:
{
Console.WriteLine(cnt);
break;
}
case 3:
{
if (cnt == 0)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine(0);
}
break;
}
case 4:
{
if (cnt == 0)
{
Console.WriteLine("-1");
}
else
{
Console.WriteLine(stack[cnt - 1]);
}
break;
}
}
}
}
}
}
}
}
'Console Programming > C# Console' 카테고리의 다른 글
백준 11654 아스키 코드 (0) | 2019.11.05 |
---|---|
백준 10809 알파벳 찾기 (0) | 2019.11.05 |
2019-10-31 Idexer, LinkedList(직접만든) 사용한 인벤토리 (0) | 2019.10.31 |
2019-10-31 System.NullReferenceException 인벤토리를 Indexer와 Linked List를 사용하여 구현 (0) | 2019.10.31 |
2019-10-31 return을 제때 사용하지 않았을 때 Indexer사용해서 인벤토리 만들기 (0) | 2019.10.31 |