[프로그래머스] Lv1. 성격 유형 검사하기

lemythe423·2023년 9월 4일
0
post-thumbnail

🔗

풀이

4를 기준으로 1~3은 앞의 알파벳을, 5~7은 뒤의 알파벳에 점수를 추가한다. 4가 기준이 되기 때문에 4를 빼주면 음수와 양수로 나눌 수 있다. 1~3점은 음수가 되기 때문에 반대로 빼주는 점만 유의하면 된다.

def solution(survey, choices):
    mbti = defaultdict(int)

    for i in range(len(survey)):
        choice = choices[i]-4
        if choice<0:
            mbti[survey[i][0]] -= choice
        elif choice>0:
            mbti[survey[i][1]] += choice

    ans = ''
    ans += 'R' if mbti['R'] >= mbti['T'] else 'T'
    ans += 'C' if mbti['C'] >= mbti['F'] else 'F'
    ans += 'J' if mbti['J'] >= mbti['M'] else 'M'
    ans += 'A' if mbti['A'] >= mbti['N'] else 'N'
    return ans

from collections import defaultdict
profile
아무말이나하기

0개의 댓글