코테준비

[2025.5.2] 백준 10845: 큐

도도돋치 2025. 5. 9. 19:14
Contents 접기
728x90

using System.Linq.Expressions;
using System.Text;

namespace CodingTest;

class Program
{
    static void Main(string[] args)
    {
        List<string> list = new List<string>();
        int front=-1;
        StringBuilder sb = new StringBuilder();

        int N=int.Parse(Console.ReadLine());
    
        for(int i=0; i<N; i++)
        {
            string[] commend = Console.ReadLine().Split(" ");
            switch(commend[0])
            {
                case "push":
                    list.Add(commend[1]);
                    break;
                case "front":
                    sb.AppendLine(list.Count==0? "-1":list[0]);
                    break;
                case "back":
                    sb.AppendLine(list.Count==0? "-1": list[list.Count-1]);
                    break;
                case "pop":
                    sb.AppendLine(list.Count==0? "-1": list[0]);
                    if(list.Count!=0) list.RemoveAt(0);
                    break;
                case "size":
                    sb.AppendLine(list.Count==0? "0":list.Count().ToString());
                    break;
                case "empty":
                    sb.AppendLine(list.Count==0? "1":"0");
                    break;
            }

        }
        Console.WriteLine(sb);

    }
}
728x90

'코테준비' 카테고리의 다른 글

[2025.5.7] 백준 1874번: 스택 수열  (0) 2025.05.07
[2025.5.2] 백준 9012: 괄호  (1) 2025.05.02
[2025.5.1] 백준 9093: 단어뒤집기  (0) 2025.05.02
[2025.4.30] 백준 10828: 스택  (0) 2025.05.01
DFS 공부  (0) 2025.04.30