공부 서랍장/알고리즘 공부

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

만땅이 2022. 9. 18. 19:08

# 문제: https://school.programmers.co.kr/learn/courses/30/lessons/118666

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

# 유형 산출 부분을 어떻게 하면 더 효율적으로 만들 수 있을까?

def solution(survey, choices):
    answer = []
    
    dic = {'R':0, 'T':0,'C':0,'F':0,'J':0,'M':0,'A':0,'N':0}

    # 유형 검사
    for survey_type, choices_num in zip(survey, choices):
        # print(survey_type, choices_num)
        if choices_num < 4:
            dic[survey_type[0]] +=  (4 - choices_num)
        elif choices_num == 4:
            pass
        elif choices_num > 4:
            dic[survey_type[1]] += (choices_num - 4)

        
    #유형 산출
    if dic['R'] > dic['T']:
        answer.append('R')
    elif dic['R'] == dic['T']:
        answer.append('R')
    else:
        answer.append('T')
        
    if dic['C'] > dic['F']:
        answer.append('C')
    elif dic['C'] == dic['F']:
        answer.append('C')
    else:
        answer.append('F')       
        
    if dic['J'] > dic['M']:
        answer.append('J')
    elif dic['J'] == dic['M']:
        answer.append('J')
    else:
        answer.append('M')      
        
    if dic['A'] > dic['N']:
        answer.append('A')
    elif dic['A'] == dic['N']:
        answer.append('A')
    else:
        answer.append('N')  
    
    return "".join(answer)
반응형