[프로그래머스] 신고 결과 받기

단간단간·2024년 5월 3일
0

알고리즘 문제

목록 보기
98/106

문제 링크:

https://school.programmers.co.kr/learn/courses/30/lessons/92334


python

def solution(id_list, report, k):
    # 유저: 해당 유저가 신고한 유저들
    reporter_dict = {name: set() for name in id_list}

    # 유저: 신고당한 횟수
    reportee_dict = {name: 0 for name in id_list}

    for report_content in report:
        reporter, reportee = report_content.split(" ")

        if reportee not in reporter_dict[reporter]:
            reporter_dict[reporter].add(reportee)
            reportee_dict[reportee] += 1

    # 각 유저별 처리 결과 메일 받은 횟수 확인
    result = []
    for id in id_list:
        count = 0
        for reportee in reporter_dict[id]:
            if reportee_dict[reportee] >= k:
                count += 1

        result.append(count)

    return result


if __name__ == "__main__":
    result = solution(
        id_list=["muzi", "frodo", "apeach", "neo"],
        report=["muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "apeach muzi"],
        k=2,
    )

    print(result)
[2, 1, 1, 0]
profile
simple is best

0개의 댓글