-
(파이썬) 프로그래머스 - [1차] 뉴스 클러스터링알고리즘/프로그래머스 2021. 10. 18. 21:10
from itertools import combinations import string def solution(str1, str2): answer = 0 a = [] b = [] for i in range(len(str1)-1): if ('a' <= str1[i] <= 'z' or 'A' <= str1[i] <= 'Z') and ('a' <= str1[i+1] <= 'z' or 'A' <= str1[i+1] <= 'Z'): a.append([str1[i].upper(),str1[i+1].upper()]) for i in range(len(str2)-1): if ('a' <= str2[i] <= 'z' or 'A' <= str2[i] <= 'Z') and ('a' <= str2[i+1] <= 'z' or 'A' <= str2[i+1] <= 'Z'): b.append([str2[i].upper(),str2[i+1].upper()]) visit = [False for _ in range(len(b))] child = 0 for i in range(len(a)): for j in range(len(b)): if a[i] == b[j] and visit[j] == False: child += 1 visit[j] = True break parent = len(a) + len(b) - child if parent == 0: answer = 65536 else: answer = int(child/parent*65536) return answer
a에 str1으로 만들 수 있는 원소를 넣었고
b에 str2로 만들 수 있는 원소를 넣었다.
parent + child = a의 길이 + b의 길이
'알고리즘 > 프로그래머스' 카테고리의 다른 글
(파이썬) 프로그래머스 - 수식 최대화 (0) 2021.10.20 (파이썬) 프로그래머스 - 거리두기 확인하기 (0) 2021.10.20 (파이썬) 프로그래머스 - 불량 사용자 (0) 2021.09.26 (MySQL) 프로그래머스 - 입양 시각 구하기(1) (0) 2021.09.26 (MySQL) 프로그래머스 - 동명 동물 수 찾기 (0) 2021.09.26