2024-03-26 23:58:30

 

N번만큼 사람들이 회사에 자유롭게 들어오고 나간다.

마지막 순간에 회사에 남아있는 사람의 이름을 출력해 주면 된다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
 
namespace 연습장
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using var reader = new StreamReader(Console.OpenStandardInput());
            using var print = new StreamWriter(Console.OpenStandardOutput());
            StringBuilder sb = new StringBuilder();
 
            int N = Convert.ToInt32(reader.ReadLine());
 
            Dictionary<stringstring> emp = new Dictionary<stringstring>();
 
            for (int i = 0; i < N; i++)
            {
                string[] door = reader.ReadLine().Split();
                if (door[1== "enter")
                    emp.Add(door[0], door[1]);
                else
                    emp.Remove(door[0]);
            }
            List<string> list = new List<string>(emp.Keys);
 
            list.Sort();
            list.Reverse();
 
            foreach (string s in list)
                sb.Append(s + "\n");
 
            print.WriteLine(sb);
 
        }
    }
}
cs

 

입력값의 두 번째가 enter이면 딕셔너리에 넣고, leave면 입력값의 첫 번째 원소를 키값으로 하는 딕셔너리의 원소를 삭제한다. 이후 딕셔너리의 키값만 따로 추출하여 새로운 리스트를 만들 때 이용한다.

리스트를 정렬 - > 역순으로 만들고, StringBuilder에 넣어서 출력해 줬다.