코딩테스트 연습 - [1차] 뉴스 클러스터링

뉴스 클러스터링 여러 언론사에서 쏟아지는 뉴스, 특히 속보성 뉴스를 보면 비슷비슷한 제목의 기사가 많아 정작 필요한 기사를 찾기가 어렵다. Daum 뉴스의 개발 업무를 맡게 된 신입사원 튜브

programmers.co.kr

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
32
33
34
35
36
37
38
39
40
41
import math
def solution(str1, str2):
    str1_result = []
    str2_result = []
 
    for i in range(len(str1) - 1):
        temp = str1[i:i + 2]
        if temp.isalpha():
            str1_result.append(temp[:].upper())
            
    for i in range(len(str2) - 1):
        temp = str2[i:i + 2]
        if temp.isalpha():
            str2_result.append(temp[:].upper())
 
    # 1인 경우
    if str1_result == [] and str2_result == []:
        return 65536
 
    # 교집합 gyo
    gyo = []
    temp_gyo = list(set(str1_result) & set(str2_result))
    for i in temp_gyo:
        count = min(str1_result.count(i), str2_result.count(i))
        s = [i] * count
        gyo += s
 
    # 합집합 hap
    hap = []
    temp_hap = list(set(str1_result) | set(str2_result))
    for i in temp_hap:
        count = max(str1_result.count(i), str2_result.count(i))
        s = [i] * count
        hap += s
 
    answer = (len(gyo) / len(hap)) * 65536
    return math.floor(answer)
 
str1 = 'E=M*C^2'
str2 = 'e=m*c^2'
print(solution(str1, str2))
cs

 


 

+ Recent posts