최대 1 분 소요

문제 링크

풀이 과정

  1. 시간 제한이 핵심인 문제이다.
  2. 입출력을 Stream객체를 통해 구현하여 시간을 절약한다.
  3. SortedSet을 이용해서 값을 넣자마자 정렬시킨다.
  4. 마지막에 역순 정렬된 SortedSet을 foreach문으로 순회하며 출력한다.

결과

internal class Program
{
    static void Main(string[] args)
    {
        StreamReader sr = new StreamReader(Console.OpenStandardInput());
        StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

        int n = int.Parse(sr.ReadLine());

        SortedSet<string> workingPeople = new SortedSet<string>();

        // 출입카드 로그
        for (int i = 0; i < n; i++)
        {
            string[] s = sr.ReadLine().Split(" ");

            if (s[1].Equals("enter"))
            {
                workingPeople.Add(s[0]);
            }
            else
            {
                workingPeople.Remove(s[0]);
            }
        }

        // 회사에 남은 사람 역순 출력
        foreach (string workingPerson in workingPeople.Reverse())
        {
            sw.WriteLine(workingPerson);
        }

        sr.Close();
        sw.Close();
    }
}

댓글남기기