Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로그래머스
- 편스토랑
- 더현대서울 맛집
- Kaggle
- Real or Not? NLP with Disaster Tweets
- github
- 금융문자분석경진대회
- 데이콘
- SW Expert Academy
- Docker
- 프로그래머스 파이썬
- ubuntu
- ChatGPT
- 캐치카페
- gs25
- dacon
- PYTHON
- leetcode
- programmers
- 백준
- 맥북
- Git
- 자연어처리
- 우분투
- hackerrank
- AI 경진대회
- Baekjoon
- 편스토랑 우승상품
- 파이썬
- 코로나19
Archives
- Today
- Total
솜씨좋은장씨
[Programmers] 2018 KAKAO BLIND RECRUITMENT : [1차] 뉴스 클러스트링 (Python) 본문
Programming/코딩 1일 1문제
[Programmers] 2018 KAKAO BLIND RECRUITMENT : [1차] 뉴스 클러스트링 (Python)
솜씨좋은장씨 2020. 4. 19. 21:31728x90
반응형
1일 1문제 73일차!
오늘의 문제는 프로그래머스의 2018 KAKAO BLIND RECRUITMENT : [1차] 뉴스클러스트링 입니다.
첫번째 제출
import re
def getTwolengthString(temp):
re_compile = re.compile('[a-z]{2}')
re_match = re.fullmatch(re_compile, temp)
return re_match
def solution(str1, str2):
str1_list = list(str1.lower())
str2_list = list(str2.lower())
str1_pattern = []
str2_pattern = []
for i in range(len(str1_list)-1):
temp = ''.join(str1_list[i:i+2])
re_match = getTwolengthString(temp)
if re_match != None:
str1_pattern.append(temp)
for i in range(len(str2_list)-1):
temp = ''.join(str2_list[i:i+2])
re_match = getTwolengthString(temp)
if re_match != None:
str2_pattern.append(temp)
print(str1_pattern)
print(str2_pattern)
data_union = set(str1_pattern).union(set(str2_pattern))
print(data_union)
data_intersection = set(str1_pattern).intersection(set(str2_pattern))
print(data_intersection)
if len(data_union) != 0:
jaccard_similarity = len(data_intersection) / len(data_union)
answer = int(jaccard_similarity * 65536)
else:
answer = 65536
return answer
결과
중복을 포함해야하는데 set 자료형을 사용하여 계산하니 중복값들이 포함되지 않아 중복값이 들어간 값들은
두번째 제출
import re
from collections import Counter
def getTwolengthString(temp):
re_compile = re.compile('[a-z]{2}')
re_match = re.fullmatch(re_compile, temp)
return re_match
def solution(str1, str2):
str1_list = list(str1.lower())
str2_list = list(str2.lower())
str1_pattern = []
str2_pattern = []
for i in range(len(str1_list)-1):
temp = ''.join(str1_list[i:i+2])
re_match = getTwolengthString(temp)
if re_match != None:
str1_pattern.append(temp)
for i in range(len(str2_list)-1):
temp = ''.join(str2_list[i:i+2])
re_match = getTwolengthString(temp)
if re_match != None:
str2_pattern.append(temp)
print(str1_pattern)
print(str2_pattern)
str1_pattern_counter = Counter(str1_pattern)
str2_pattern_counter = Counter(str2_pattern)
print(str1_pattern_counter)
print(str2_pattern_counter)
data_union = set(str1_pattern).union(set(str2_pattern))
print(data_union)
data_intersection = set(str1_pattern).intersection(set(str2_pattern))
print(data_intersection)
data_union_sum = 0
data_intersection_sum = 0
str1_key = str1_pattern_counter.keys()
str2_key = str2_pattern_counter.keys()
for uni in data_union:
if uni in str1_key:
num1 = str1_pattern_counter[uni]
if uni in str2_key:
num1 = max(num1, str2_pattern_counter[uni])
data_union_sum = data_union_sum + num1
for uni in data_intersection:
if uni in str1_key:
num1 = str1_pattern_counter[uni]
if uni in str2_key:
num1 = min(num1, str2_pattern_counter[uni])
data_intersection_sum = data_intersection_sum + num1
if data_union_sum != 0:
jaccard_similarity = data_intersection_sum / data_union_sum
answer = int(jaccard_similarity * 65536)
print(jaccard_similarity)
else:
answer = 65536
return answer
결과
세번째 제출
import re
from collections import Counter
def getTwolengthString(temp):
re_compile = re.compile('[a-z]{2}')
re_match = re.fullmatch(re_compile, temp)
return re_match
def solution(str1, str2):
str1_list = list(str1.lower())
str2_list = list(str2.lower())
str1_pattern = []
str2_pattern = []
for i in range(len(str1_list)-1):
temp = ''.join(str1_list[i:i+2])
re_match = getTwolengthString(temp)
if re_match != None:
str1_pattern.append(temp)
for i in range(len(str2_list)-1):
temp = ''.join(str2_list[i:i+2])
re_match = getTwolengthString(temp)
if re_match != None:
str2_pattern.append(temp)
print(str1_pattern)
print(str2_pattern)
str1_pattern_counter = Counter(str1_pattern)
str2_pattern_counter = Counter(str2_pattern)
print(str1_pattern_counter)
print(str2_pattern_counter)
data_union = str1_pattern_counter | str2_pattern_counter
print(data_union)
data_intersection = str1_pattern_counter & str2_pattern_counter
print(data_intersection)
data_union_sum = 0
data_intersection_sum = 0
data_union_sum = sum(list(data_union.values()))
data_intersection_sum = sum(list(data_intersection.values()))
if data_union_sum != 0:
jaccard_similarity = data_intersection_sum / data_union_sum
answer = int(jaccard_similarity * 65536)
print(jaccard_similarity)
elif data_union_sum == 0:
answer = 65536
elif data_intersection_sum == 0:
answer = 0
return answer
결과
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[BaekJoon] 2011번 : 암호코드 (Python) (0) | 2020.04.22 |
---|---|
[Programmers] 스택/큐 : 쇠막대기 (Python) (0) | 2020.04.20 |
[BaekJoon] 10773번 : 제로 (Python) (0) | 2020.04.18 |
[Programmers] Summer/Winter Coding(~2018) : 영어 끝말잇기 (Python) (0) | 2020.04.17 |
[Programmers] Summer/Winter Coding(~2018) : 소수 만들기 (Python) (0) | 2020.04.16 |
Comments