[Programmers/프로그래머스] 2019 KAKAO BLIND RECRUITMENT [코딩테스트]
- [Lv. 2] 오픈채팅방
- [Lv. 1] 실패율
- [Lv. 2] 후보키
- [Lv. 4] 무지의 먹방 라이브
- [Lv. 3] 길 찾기 게임
- [Lv. 3] 매칭 점수
- [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
linked_page_dict[link].append(title)
match_score = []
for title in basic_score_dict:
link_score = 0
if title in linked_page_dict:
for link in linked_page_dict[title]:
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))