본문 바로가기

코딩

[Python] 백준 #7785. 회사에 있는 사람

https://www.acmicpc.net/problem/7785

 

7785번: 회사에 있는 사람

첫째 줄에 로그에 기록된 출입 기록의 수 n이 주어진다. (2 ≤ n ≤ 106) 다음 n개의 줄에는 출입 기록이 순서대로 주어지며, 각 사람의 이름이 주어지고 "enter"나 "leave"가 주어진다. "enter"인 경우는

www.acmicpc.net

 

# 7785 - Python 3

import sys

input = sys.stdin.readline

k = int(input())
name_dict = dict()                      

for _ in range(k):
    name, working = input().split()

    if working == "enter":
        name_dict[name] = 1
    elif working == "leave":
        name_dict[name] = 0

name_list = sorted(name_dict.items(), key = lambda x : x[0], reverse = True)

for name, working in name_list:
    if working:
        print(name)

'코딩' 카테고리의 다른 글

[Python] 백준 #2745. 진법 변환  (0) 2023.06.20
[Python] 백준 #1874. 스택 수열  (0) 2023.03.31
[Python] 백준 #4949. 균형잡힌 세상  (0) 2023.03.31
[Python] 백준 #9012. 괄호  (0) 2023.03.30
[Python] 백준 #24723. 녹색거탑  (0) 2023.03.30