less than 1 minute read

1. 개요

2. 풀이

def solution(surveys, choices):
    # 대응되는 성격들을 딕셔너리로 만든다.
    # 키가 밸류보다 항상 앞에 오도록 한다.
    compared = {"R":"T", "C":"F", "J":"M", "A":"N"}
    scores = {"R":0, "C":0, "J":0, "A":0, "T":0, "F":0, "M":0, "N":0}
    choicer = [0,3,2,1,0,1,2,3] # 선택지를 점수로 변환한다.
    answer = []
    
    for survey, choice in zip(surveys, choices):
        left, right = survey[0], survey[1]
        
        # 선택지가 4미만이라면 왼쪽에 점수를 준다.
        # 아니라면 그 반대에 점수를 준다.
        if choice < 4:
            scores[left] += choicer[choice]
        else:
            scores[right] += choicer[choice]

    # 점수를 비교해서 높은쪽이 성격이 된다.
    for left in compared:
        right = compared[left]

        if scores[left] >= scores[right]:
            answer.append(left)
        else:
            answer.append(right)

    return ''.join(answer)

Leave a comment