๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐˜ผ๐™ก๐™œ๐™ค๐™ง๐™ž๐™ฉ๐™๐™ข/๐™‹๐™ง๐™ค๐™œ๐™ง๐™–๐™ข๐™ข๐™š๐™ง๐™จ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2018 KAKAO BLIND RECRUITMENT[1์ฐจ] '๋‰ด์Šค ํด๋Ÿฌ์Šคํ„ฐ๋ง' ํŒŒ์ด์ฌ ํ’€์ด

by beomcoder 2023. 2. 22.
728x90
๋ฐ˜์‘ํ˜•
 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

"""
์—ฌ๋Ÿฌ ์–ธ๋ก ์‚ฌ์—์„œ ์Ÿ์•„์ง€๋Š” ๋‰ด์Šค, ํŠนํžˆ ์†๋ณด์„ฑ ๋‰ด์Šค๋ฅผ ๋ณด๋ฉด ๋น„์Šท๋น„์Šทํ•œ ์ œ๋ชฉ์˜ ๊ธฐ์‚ฌ๊ฐ€ ๋งŽ์•„
์ •์ž‘ ํ•„์š”ํ•œ ๊ธฐ์‚ฌ๋ฅผ ์ฐพ๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค. Daum ๋‰ด์Šค์˜ ๊ฐœ๋ฐœ ์—…๋ฌด๋ฅผ ๋งก๊ฒŒ ๋œ ์‹ ์ž…์‚ฌ์› ํŠœ๋ธŒ๋Š”
์‚ฌ์šฉ์ž๋“ค์ด ํŽธ๋ฆฌํ•˜๊ฒŒ ๋‹ค์–‘ํ•œ ๋‰ด์Šค๋ฅผ ์ฐพ์•„๋ณผ ์ˆ˜ ์žˆ๋„๋ก ๋ฌธ์ œ์ ์„ ๊ฐœ์„ ํ•˜๋Š” ์—…๋ฌด๋ฅผ ๋งก๊ฒŒ ๋˜์—ˆ๋‹ค.

์ž์นด๋“œ ์œ ์‚ฌ๋„๋Š” ์ง‘ํ•ฉ ๊ฐ„์˜ ์œ ์‚ฌ๋„๋ฅผ ๊ฒ€์‚ฌํ•˜๋Š” ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ• ์ค‘์˜ ํ•˜๋‚˜๋กœ ์•Œ๋ ค์ ธ ์žˆ๋‹ค.
๋‘ ์ง‘ํ•ฉ A, B ์‚ฌ์ด์˜ ์ž์นด๋“œ ์œ ์‚ฌ๋„ J(A, B)๋Š” ๋‘ ์ง‘ํ•ฉ์˜ ๊ต์ง‘ํ•ฉ ํฌ๊ธฐ๋ฅผ
๋‘ ์ง‘ํ•ฉ์˜ ํ•ฉ์ง‘ํ•ฉ ํฌ๊ธฐ๋กœ ๋‚˜๋ˆˆ ๊ฐ’์œผ๋กœ ์ •์˜๋œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ์ง‘ํ•ฉ A = {1, 2, 3}, ์ง‘ํ•ฉ B = {2, 3, 4}๋ผ๊ณ  ํ•  ๋•Œ,
๊ต์ง‘ํ•ฉ A ∩ B = {2, 3}, ํ•ฉ์ง‘ํ•ฉ A ∪ B = {1, 2, 3, 4}์ด ๋˜๋ฏ€๋กœ,
์ง‘ํ•ฉ A, B ์‚ฌ์ด์˜ ์ž์นด๋“œ ์œ ์‚ฌ๋„ J(A, B) = 2/4 = 0.5๊ฐ€ ๋œ๋‹ค.
์ง‘ํ•ฉ A์™€ ์ง‘ํ•ฉ B๊ฐ€ ๋ชจ๋‘ ๊ณต์ง‘ํ•ฉ์ผ ๊ฒฝ์šฐ์—๋Š” ๋‚˜๋ˆ—์…ˆ์ด ์ •์˜๋˜์ง€ ์•Š์œผ๋‹ˆ 
๋”ฐ๋กœ J(A, B) = 1๋กœ ์ •์˜ํ•œ๋‹ค

(์ค‘๋žต)
"""

def solution(str1, str2):
    answer = 0
    s1 = [str1[i].lower()+str1[i+1].lower() for i in range(len(str1)-1) if ('a'<=str1[i].lower()<='z' and 'a'<=str1[i+1].lower()<='z')]
    s2 = [str2[i].lower()+str2[i+1].lower() for i in range(len(str2)-1) if ('a'<=str2[i].lower()<='z' and 'a'<=str2[i+1].lower()<='z')]
    
    numerator = 0
    
    for v in s1:
        if v in s2:
            s2.remove(v)
            numerator+=1
            
    denominator = len(s1+s2)
    
    if numerator==0 and denominator==0:
        return 65536
    
    return int(numerator/denominator*65536)
    
"""
-> "FRANCE"์™€ "FRENCH"๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ด๋ฅผ ๋‘ ๊ธ€์ž์”ฉ ๋Š์–ด์„œ ๋‹ค์ค‘์ง‘ํ•ฉ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.
๊ฐ๊ฐ {FR, RA, AN, NC, CE}, {FR, RE, EN, NC, CH}๊ฐ€ ๋˜๋ฉฐ ์ด๋•Œ ์˜๋ฌธ์ž๋กœ ๋œ ๊ธ€์ž ์Œ๋งŒ ์œ ํšจํ•˜๊ณ ,
๊ธฐํƒ€ ๊ณต๋ฐฑ์ด๋‚˜ ์ˆซ์ž, ํŠน์ˆ˜ ๋ฌธ์ž๊ฐ€ ๋“ค์–ด์žˆ๋Š” ๊ฒฝ์šฐ๋Š” ๊ทธ ๊ธ€์ž ์Œ์„ ๋ฒ„๋ฆฐ๋‹ค.

์—ฌ๊ธฐ์„œ ๋จผ์ € str1์˜ ์ง‘ํ•ฉ๊ณผ str2์˜ ์ง‘ํ•ฉ์„ ๋งŒ๋“ค์–ด์•ผ ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ์˜๋ฌธ์ž๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด ์ง‘ํ•ฉ์— ์ถ”๊ฐ€ํ•˜๋ฉด ์•ˆ๋˜๋‹ˆ ์กฐ๊ฑด์„ ์ถ”๊ฐ€ํ•˜์˜€๋‹ค.
str1[i]+str1[i+1]์ด ์ „๋ถ€ ์˜๋ฌธ์ž๋ผ๋ฉด ์ง‘ํ•ฉ์— ์ถ”๊ฐ€ํ–ˆ๊ณ , ์•„๋‹ˆ๋ผ๋ฉด ๋„ฃ์ง€ ์•Š์•˜๋‹ค.

๊ทธ ๋‹ค์Œ์€ ๊ต์ง‘ํ•ฉ๊ณผ ํ•ฉ์ง‘ํ•ฉ์„ ๊ตฌํ•˜๋ฉด ๋œ๋‹ค.
๊ต์ง‘ํ•ฉ์€ s1์ง‘ํ•ฉ์„ ํ•˜๋‚˜์”ฉ ๊ฐ€์ ธ์™€์„œ s2์— ๊บผ๋‚ด์˜จ๊ฒŒ ์žˆ์œผ๋ฉด ๊ต์ง‘ํ•ฉ์˜ ๊ฐœ์ˆ˜๋ฅผ 1๊ฐœ ๋Š˜๋ ธ๋‹ค.
์—ฌ๊ธฐ์„œ s2.remove๋ฅผ ํ•œ ์ด์œ ๋Š” ํ•ฉ์ง‘ํ•ฉ์„ ๊ณ„์‚ฐํ• ๋•Œ s1์™€ s2์˜ ์ค‘๋ณต์„ ์ง€์›Œ์•ผ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๋‘˜๋‹ค ๊ต์ง‘ํ•ฉ๊ณผ ํ•ฉ์ง‘ํ•ฉ์ด ๊ณต์ง‘ํ•ฉ์ด๋ผ๋ฉด 65536์„ ๋ฆฌํ„ดํ•˜๊ณ 
์•„๋‹ˆ๋ผ๋ฉด ๊ณ„์‚ฐํ•˜์—ฌ ๋ฆฌํ„ดํ•ด์ฃผ์—ˆ๋‹ค.
"""
728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€