프로그래머스

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

yanJuicy 2024. 2. 10. 14:34
반응형

문제

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

 

풀이

신고를 받은 횟수와 신고를 한 id를 함께 저장하기 위해 다음 형태로 딕셔너리를 만든다.

{"신고 당한 id": ["신고한 id1", "신고한 id2"]}

신고 당한 id 키에 해당하는 값 리스트의 길이가 k 보다 크면 이용 정지가 된다.

그러면 리스트에 있는 신고한 id 마다 메일 받는 횟수를 1 증가시킨다.

 

 

코드

python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def solution(id_list, report, k):
    user_receive_mail_dic = {}
    for id in id_list:
        user_receive_mail_dic[id] = 0
    
    report_dic = {}
    for r in report:
        id, report_id = r.split()
        if report_id not in report_dic:
            report_dic[report_id] = []
        if id not in report_dic[report_id]:
            report_dic[report_id].append(id)
        
    for report_key in report_dic.keys():
        if len(report_dic[report_key]) >= k:
            for id in report_dic[report_key]:
                user_receive_mail_dic[id] += 1
 
    answer = list(user_receive_mail_dic.values())
    return answer
cs

 

반응형