반응형

2018 KAKAO BLIND RECRUITMENT 문제이다.

문제 풀이

 1. 먼저 문자열을 2자씩 끊은 후, 정규표현식을 이용하여 두자가 모두 알파벳으로 되어있는지 확인한다.

 2. 두자 모두 알파벳으로 되어있다면 str1, str2 각각의 리스트에 모두 소문자로 바꾸어 넣어준다.("FR"과 "fr"을 같은 단어로 인식하기 위함으로 꼭 소문자가 아니더라도 둘의 양식을 맞춰주면 된다.)

 3. 합집합과 교집합의 원소의 수를 세어 자카드 유사도를 반환한다.

Python Code

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
import re
 
def solution(str1, str2):
    checker = re.compile('[a-zA-Z]{2}')
    answer = 0
    
    token1 = []
    token2 = []
    # tokenize
    for i in range(len(str1)-1):
        t1 = str1[i:i+2]
        if checker.match(t1) != None:
            token1.append(t1.lower())
    for i in range(len(str2)):
        t2 = str2[i:i+2]
        if checker.match(t2) != None:
            token2.append(t2.lower())
    
    intersection = 0
    union = 0
    
    for t in token1:
        if t in token2:
            intersection+=1
            union += 1
            token2.remove(t)
        else :
            union+=1
    union += len(token2)
    return int((intersection/union) * 65536if intersection+union != 0 else 65536
cs

문제 링크

 

프로그래머스

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

programmers.co.kr

 

반응형

+ Recent posts