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

DARTZ·2022년 6월 27일
0

알고리즘

목록 보기
94/135
def solution(id_list, report, k):
    final_count = {}
    report_history = {}
    report_count = {}
    ban_list = []

    for i in id_list:
        report_history[i] = []
        report_count[i] = 0
        final_count[i] = 0

    for r in report:
        reporter, reported = r.split(' ')

        if reported not in report_history[reporter]:
            report_history[reporter].append(reported)

            if reported in report_count:
                report_count[reported] += 1

    for c in report_count:
        if report_count[c] >= k:
            ban_list.append(c)

    for rh in report_history:
        for h in report_history[rh]:
            if h in ban_list:
                final_count[rh] += 1

    answer = [final_count[f] for f in final_count]

    return answer

딕셔너리로 풀었다.

  • report_history에는 사용자가 신고한 사용자들이 담겨있다.
  • report_count에는 신고당한 사용자의 신고 당한 횟수가 담겨있다.
  • ban_list에는 k이상 신고당한 유저들의 이름이 담겨 있다.
  • final_count에는 받은 메일 갯수가 담겨져 있다.
profile
사람들이 비용을 지불하고 사용할 만큼 가치를 주는 서비스를 만들고 싶습니다.

0개의 댓글