알고리즘

[프로그래머스 Lv1 - 2022 KAKAO TECH INTERNSHIP] 성격 유형 검사하기 (Python)

lwkejpf 2022. 9. 7. 12:07

 

누가 봐도 mbti 에서 영감받은 문제였던 것임 ,,

 

 

 


 

 

 

from collections import defaultdict

alpha = [['R', 'T'], ['C', 'F'], ['J', 'M'], ['A', 'N']]
li = defaultdict(int)

def solution(survey, choices):
    answer = ''
    for i in range(len(survey)) :
        if choices[i] < 4 :
            li[survey[i][0]] += 1
        elif choices[i] > 4 :
            li[survey[i][1]] += 1
    for al in alpha :
        answer += comp(al[0], al[1])
    return answer

def comp(f, s):
    if li[f] > li[s] :
        return f
    elif li[f] < li[s] :
        return s
    else :
        return sorted([f, s])[0]

 

 

ㅎㅎ 레벨 1이라고 정신 안 차렸나봄

+3, +2, +1 이렇게 점수 차이 있는 걸 생각 안 함

 

 

 

 

 

from collections import defaultdict

alpha = [['R', 'T'], ['C', 'F'], ['J', 'M'], ['A', 'N']]
li = defaultdict(int)

def solution(survey, choices):
    answer = ''
    for i in range(len(survey)) :
        if choices[i] < 4 :
            li[survey[i][0]] += (4-choices[i])
        elif choices[i] > 4 :
            li[survey[i][1]] += (choices[i]-4)
    for al in alpha :
        answer += comp(al[0], al[1])
    return answer

def comp(f, s):
    if li[f] == li[s] :
        return f
    elif li[f] < li[s] :
        return s
    else :
        return sorted([f, s])[0]

 

그냥 defaultdict 로 다 초기화해놓고 점수 비교한 게 다인 듯

암튼 앞으로 문제 꼬박꼬박 풀겠읍니다