나의 개발일지

[프로그래머스] [KAKAO] Lv.1 성격 유형 검사하기 [Python, 파이썬] 본문

프로그래머스

[프로그래머스] [KAKAO] Lv.1 성격 유형 검사하기 [Python, 파이썬]

YoonJuHan 2023. 4. 6. 11:26
def solution(survey, choices):
    answer = ''
    check = { 'R' : 0,
              'T' : 0,
              'C' : 0,
              'F' : 0,
              'J' : 0,
              'M' : 0,
              'A' : 0,
              'N' : 0 }

    for i in range(len(survey)):    # 점수 집계
        if choices[i] < 4:      # 1, 2, 3을 선택
            check[survey[i][0]] += 4 - choices[i]
        elif choices[i] > 4:    # 5, 6, 7을 선택
            check[survey[i][1]] += choices[i] - 4
    
    # 점수가 같으면 알파벳 순서상으로 먼저인 것을 선택
    if check['R'] >= check['T']:
        answer += 'R'
    else: answer += 'T'
    if check['C'] >= check['F']:
        answer += 'C'
    else: answer += 'F'
    if check['J'] >= check['M']:
        answer += 'J'
    else: answer += 'M'
    if check['A'] >= check['N']:
        answer += 'A'
    else: answer += 'N'

    return answer
Comments