Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

:)

[프로그래머스]신고 결과 받기, [프로그래머스]양궁대회 본문

Algorithm(python)

[프로그래머스]신고 결과 받기, [프로그래머스]양궁대회

mihee 2022. 10. 8. 18:46

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

 

프로그래머스

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

programmers.co.kr

구현

1. report에 대한 신고 유저, 신고 아이디 딕셔너리 만들기

2. Counter 함수로 신고 횟수 구하기

3. 신고 기준 횟수가 넘어가는 신고 아이디 리스트 만들기

4. 신고 아이디 리스트 포함 & 딕셔너리 value에 있는 개수 구해서 answer 리스트 만들기

 

from collections import Counter,defaultdict

def solution(id_list, report, k):
    answer = []
    dic = defaultdict(set)
    report_count = Counter()
    
    for r in report:
        user_id, report_id = r.split()
        dic[user_id].add(report_id)
        
    
    for _, report_id in dic.items():
        report_count.update(report_id)
    
    singo  = {x for x in report_count if report_count[x] >= k}

    for id in id_list:
        answer.append(len(dic[id] & singo)) 

    return answer

 

 

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

 

프로그래머스

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

programmers.co.kr

 

Comments