[Programmers/프로그래머스] 2019 KAKAO BLIND RECRUITMENT 매칭 점수 - Python/파이썬 [해설/풀이]

SihoonCho·2022년 11월 27일
0
post-thumbnail
[Programmers/프로그래머스] 2019 KAKAO BLIND RECRUITMENT [코딩테스트]
  1. [Lv. 2] 오픈채팅방
  2. [Lv. 1] 실패율
  3. [Lv. 2] 후보키
  4. [Lv. 4] 무지의 먹방 라이브
  5. [Lv. 3] 길 찾기 게임
  6. [Lv. 3] 매칭 점수
  7. [Lv. 4] 블록 게임

📌 문제


📝 제한사항


💻 입출력 예


<html lang="ko" xml:lang="ko" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta property="og:url" content="https://a.com"/>
</head>
<body>
Blind Lorem Blind ipsum dolor Blind test sit amet, consectetur adipiscing elit. 
<a href="https://b.com"> Link to b </a>
</body>
</html>
<html lang="ko" xml:lang="ko" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta property="og:url" content="https://b.com"/>
</head>
<body>
Suspendisse potenti. Vivamus venenatis tellus non turpis bibendum, 
<a href="https://a.com"> Link to a </a>
blind sed congue urna varius. Suspendisse feugiat nisl ligula, quis malesuada felis hendrerit ut.
<a href="https://c.com"> Link to c </a>
</body>
</html>
<html lang="ko" xml:lang="ko" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta property="og:url" content="https://c.com"/>
</head>
<body>
Ut condimentum urna at felis sodales rutrum. Sed dapibus cursus diam, non interdum nulla tempor nec. Phasellus rutrum enim at orci consectetu blind
<a href="https://a.com"> Link to a </a>
</body>
</html>

<html lang="ko" xml:lang="ko" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta property="og:url" content="https://careers.kakao.com/interview/list"/>
</head>
<body>
<a href="https://programmers.co.kr/learn/courses/4673"></a>#!MuziMuzi!)jayg07con&&

</body>
</html>
<html lang="ko" xml:lang="ko" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta property="og:url" content="https://www.kakaocorp.com"/>
</head>
<body>
con%    muzI92apeach&2<a href="https://hashcode.co.kr/tos"></a>

    ^
</body>
</html>

📖 입출력 예에 대한 설명


📌 풀이


import re
from collections import defaultdict

def solution(word, pages):
    basic_score_dict = {}
    link_count_dict = {}
    linked_page_dict = defaultdict(list)
    for page in pages:
        title = re.search('<meta property="og:url" content="(\S+)"', page).group(1)
        basic_score_dict[title] = 0
        link_count_dict[title] = 0
        
        # 기본점수계산, 검색어 등장 횟수탐색
        for keyword in re.findall('[a-zA-Z]+', page):
            if word.lower() == keyword.lower():
                basic_score_dict[title] += 1
        # 외부링크 연결개수 탐색
        for link in re.findall('<a href="(https://\S+)"', page):
            link_count_dict[title] += 1             # title페이지에서 외부 페이지로 연결된 링크 수
            linked_page_dict[link].append(title)    # link페이지로 링크가 걸린 title페이지
    
    match_score = []
    for title in basic_score_dict:      # 각각의 title페이지에 대해
        link_score = 0
        if title in linked_page_dict:   # title페이지로 링크가 걸린 다른 웹페이지가 존재한다면
            for link in linked_page_dict[title]:    # 그 다른 각각의 웹페이지 link에 대해
                link_score += basic_score_dict[link] / link_count_dict[link]
        match_score.append(basic_score_dict[title] + link_score)
            
    return match_score.index(max(match_score))
profile
개발을 즐길 줄 아는 백엔드 개발자

0개의 댓글

Powered by GraphCDN, the GraphQL CDN