반응형
문제
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 |
반응형
'프로그래머스' 카테고리의 다른 글
프로그래머스 - 네트워크 (0) | 2024.06.03 |
---|---|
프로그래머스 - 게임 맵 최단거리 (0) | 2024.04.15 |
프로그래머스 - 할인 행사 (1) | 2024.02.06 |
프로그래머스 - 완주하지 못한 선수 (0) | 2024.02.02 |
프로그래머스 - 다리를 지나는 트럭 (0) | 2024.02.02 |