코딩테스트/프로그래머스

[프로그래머스] [Level 2] [2018 KAKAO BLIND RECRUITMENT 1차] 뉴스 클러스터링

박소민 2022. 9. 27. 16:44
뉴스 클러스터링
 

프로그래머스

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

programmers.co.kr

 

  • 내 풀이
def solution(str1, str2):
    answer=0
    str1=str1.upper()
    str2=str2.upper()
    x=""
    a=[]
    b=[]
    n,m=0,0
    for i in range(len(str1)-1):
        x=str1[i:i+2]
        if x.isalpha(): #알파벳일 경우만
            a.append(x)
    for i in range(len(str2)-1):
        x=str2[i:i+2]
        if x.isalpha(): 
            b.append(x)
    ls=list(set(a+b))
    
    for l in ls:
        if l not in a and l not in b:
            continue
        elif l in a and l in b:
            n+=min(a.count(l), b.count(l))
        m+=max(a.count(l), b.count(l))
    if m==0:
        return 65536
    return int((n/m)*65536)
str1, str2= "FRANCE", "french"
str1, str2= "handshake", "shake hands"
str1, str2= "aa1+aa2", "AAAA12"
str1, str2= "E=M*C^2", "e=m*c^2"

#결과
16384
65536
43690
65536